Loops are a type of control flow structure, in which, a series of statements may be executed repeatedly until some condition is met.

learn more… | top users | synonyms

0
votes
0answers
10 views

Pausing a SwingWorker with a Timer

I made a SwingWorker which is fetching tweets using the twitter4j API. The twitter API will allow 180 queries every 15 minutes, and then throw an exception with ...
3
votes
3answers
152 views

More efficient and readable nested loop to compare keywords

I've created an algorithm which weighs the relevance of a list of articles against two lists of keywords that correlate to attributes of the article. It works great and is super efficient... but it's ...
2
votes
0answers
33 views

Where is the bottleneck in my Cython code?

The profile tells me it took ~15s to run, but without telling me more. ...
7
votes
1answer
94 views

Incrementing letter-spacing of one line of text

I was asked to create a script which will increment the letter-spacing of one line of text, until its width matches that of the first line; for use in headline/subheadline text to maintain a block ...
6
votes
1answer
263 views

Sorting numbers into bins

I have two 2D arrays of doubles a and b. Both have two rows and different numbers of columns. ...
4
votes
2answers
59 views

Finding matching strings in a column

I have col D (in sheet1 called Students), col A (in Sheet2 called Students too) and col B ...
-2
votes
1answer
47 views

LINQ equivalent of nested for loop to select and combine each element from two different lists [closed]

I have two lists defined as such (which represent X and Y points) ...
3
votes
1answer
39 views

Showing the domain of a URL

I have such a method which takes a URL, such as http://twitter.com/ttt or twitter.com/dasd, and should show its domain with http: http://twitter.com and name twitter ...
3
votes
2answers
68 views

While loop uses extra variables - can this be cleaned up?

A piece of my program allows the looping and incrementing of a targeted entity to be used in a while loop somewhere else. Here is a sample of the while loop: ...
5
votes
3answers
87 views

Assigning value to cells with Excel VBA

I have an Excel Worksheet consisting of two columns, one of which is filled with strings and the other of which is empty. I would like to use VBA to assign the value of the cells in the empty column ...
3
votes
1answer
107 views

Is this roulette selection extension method beautiful or disgusting?

So I just wrote the following extension method to do roulette selection on a generic list. I'm specifically unsure of the use of the while loop. Is this beautiful or a disgusting mess? ...
1
vote
6answers
111 views

Looping through an array of strings containing approximately 3 million lines of strings

I have a function that loops through an array of strings containing approximately 3 million lines of strings. My problem is this loop is running too slowly and I want to know how to make it faster. ...
4
votes
1answer
54 views

Periodically checking for internet connection

I have a SwingWorker which checks periodically for an internet connection and updates a jLabel accordingly. ...
6
votes
2answers
72 views

Basic Imitation of C# Enumerable in VBA - or any other static class

Since implementing static classes in VBA actually seems possible I came up with an idea to try to imitate C#' Enumerable class (well, to some extent...). This is ...
1
vote
2answers
277 views

Printing the sums of numbers from 1 to 10 with only 1 loop

The code below prints sum from 1 to 10: 1 1+2 = 1+2+3 = 1+2+3+4 = ...... 1 + ... 10 = 55 ...
2
votes
3answers
79 views

Foreach loop to generate HTML table with title in first cell of each row in PHP

I've used quite a lot of foreach loops to achieve this type of HTML table that has titles in the first cell of each row: ...
7
votes
3answers
373 views

Ticket management system

I am building a ticket management system for a state server we use at work. Back end is node.js with multiple front ends. I am rewriting my back end to be more maintainable as the scope grows. For ...
5
votes
3answers
47 views

Faster way to group email-date pairs by date without many nested for loops?

Given list of pairs (email-date): ...
0
votes
0answers
12 views

Using ArrayList instead of an array to avoid using a normal for loop [migrated]

I'm reviewing a piece of code that looks like this: ...
6
votes
1answer
104 views

Improving performance for Codility max slice swap problem

Problem Description: Find the maximum sum of a compact subsequence of array elements after performing a single swap operation. Solution: ...
3
votes
2answers
43 views

More efficient way to draw bufferedimage into another

For what I'm doing, I need to be able to draw a buffered image directly into a larger buffered image. I've searched around a little and still have failed to find a better way, but my current way is ...
3
votes
2answers
67 views

Multiple loops versus multiple stringbuilders

I've come across the following piece of code in a Razor view ...
7
votes
1answer
92 views

Perfect game loop

I've been working on development for an Android game, and this is the game loop I have so far: ...
5
votes
1answer
61 views

Efficiently matching IP addresses with a list of CIDRs

I am using Python3 to extract some information from a dictionary that contains 10k of CIDRs, but the running time is pretty long. Here is my purpose: I have a dictionary of CIDRs (10000) and a list ...
5
votes
1answer
67 views

ListBox Update Handling

I have UserGroups for Users to be assigned to in a ListBox in HTML form. Items from listbox can be multi-selected or completely ...
2
votes
2answers
59 views

List of search results using Selenium

I have written the following code for looping through WebElements in Selenium. Can someone please provide me with feedback on how to improve my code? ...
1
vote
2answers
53 views

Looking for matching names among two text files

I'm trying to enhance the execution speed of my below code. I am using only vanilla JavaScript. I would be willing to bring in additional libraries and plugins as long as they will enhance the overall ...
7
votes
3answers
111 views

Numerically stable sum of `double`s

It's known that if you naively sum up a collection of arbitrary floating-point numbers using any floating-point standard (e.g. floats or ...
2
votes
1answer
102 views

Sum the Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. ...
5
votes
1answer
66 views

List files and download

The following code list all files in a folder and allows the user to download one of them. It is working but I think it could be done better. Is there a way to reduce the number of forms to only one ...
7
votes
3answers
153 views

Compare string with wildcard string

I have the following function to compare a string with a wildcard string (containing ? and *), as C# doesn't seem to have a builtin function to do it. ...
2
votes
3answers
39 views

Is it possible to simplify two for loops and a foreach?

I'm writing a PHP function to collect data from different positions in an given array. I've done it as follows which gives me what I require. ...
0
votes
2answers
159 views

Optimization and less code in for loop

How to do optimization and provide less of code here: ...
1
vote
2answers
321 views

The efficiency of looping over nested dictionaries in Python

How to make the following code more efficient? ...
1
vote
0answers
18 views

Editing Surfaces Removing Color

So I have recently tried to load an image and save it, but remove all of a certain color. I'm running the program and it is running really slow, is there a more efficient way to edit an image? My code ...
3
votes
2answers
60 views

Java Cross with characters

I managed to make a perfectly even cross with for loops. I'm trying to make this cross easier to code. I have to keep it with ...
-2
votes
1answer
50 views

Optimizimg ugly if else loop in python [closed]

So, I`m getting some values from large nested dictionary. s_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] and f_copy['productStyleVariantSizeInfo']['sizeDimension2SizeOptions'] ...
3
votes
2answers
333 views

Check winner in a Tic Tac Toe game

I have the below code to check for a winner in a Tic Tac Toe game. I'm wondering if this is a good approach, and if there is a better way of doing this (maybe by monitoring the state of the board). ...
7
votes
4answers
325 views

Ruby-ize for loop - counting all the n-digit numbers that contain the digit 5 anywhere

I wrote this a while back when my fiance was taking a Number Theory class. I wrote about it here and it recently came back to my attention. Anytime I write a for ...
0
votes
1answer
55 views

For and if loops in Python math game [closed]

I'm trying to get my program to iterate through a loop after a person gets the correct answers to the first question. I feel like there is a better way to do things syntactically. ...
4
votes
1answer
139 views

Optimize PHP foreach loops

By any means, if any can tell me if this code can be more optimized than it already is, please say so. It's a select statement to my PDO class. When I glare over my code, I'm certain there is a lot of ...
10
votes
6answers
2k views

Beehive numbers - using goto in C++

I understand that using goto in C++ code is strictly unadvised, but sometimes, it really reduces the number of lines of code like in the following case. This is my ...
4
votes
1answer
117 views

Simple parallel foreach loop code correctness

I have both the regular for each loop and its equivalent paralleled version. The loop simply iterates through a collection, looking for the rate key in a local db ...
6
votes
2answers
125 views

Tight loop, string manipulation and calculations

I'm working on some precompilation operations for a world compiler. Currently to identify flags placed by the level designer I need recognize when a specific entity exists at specific coordinates from ...
11
votes
3answers
480 views

Simple integer range for C++11 range-based for loops

I'm really tired of having to type for (int iSomething = rangeBegin; iSomething < rangeEnd; ++iSomething) { ... } whenever I want to iterate over an ...
1
vote
1answer
46 views

Robots files generation - simplifying foreach code

I'm trying to figure out if there's a way I can simplify this code which is used to generate a robots.txt file with numerous rules. Different files/folders are separated in separate arrays because ...
2
votes
2answers
194 views

Making a nested loop structure more pythonic

I'm looking for a review on my code. I am also looking for ways to transform this function into something more Pythonic. I'm fairly new to Python, so any advice would be appreciated. ...
10
votes
6answers
1k views

Find the maximum number of consecutive zeros in an array

Question: To find the maximum number of consecutive zeros in a given array. Example: Input: \${1, 2, 0, 0, 2, 4, 0, 2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 0}\$ Output: "Maximum number ...
2
votes
1answer
51 views

Performance for, foreach and for key

I have a question about of the performance of using for loops (normal for, for each and for key in object) in JavaScript. Just now I created this code to test: ...