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

learn more… | top users | synonyms

2
votes
1answer
31 views

Multiple loops versus multiple stringbuilders

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

Perfect game loop

I've been working on development for an Android game, and this is the game loop I have so far: ...
0
votes
0answers
16 views

error in a while loop [on hold]

I'm trying to read a file and put the information in a matrix, but I'm getting a syntax error: syntax error at perl.pl line 12, near "){" syntax error at perl.pl line 16, near "}" Thanks! ...
5
votes
1answer
51 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 ...
4
votes
0answers
47 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 ...
0
votes
0answers
16 views

Mutation to Lists; Values not mutating correctly [closed]

Purpose of code is as follows: My code is as follows: ...
2
votes
2answers
51 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
48 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
101 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
96 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
63 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
116 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
34 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
156 views

Optimization and less code in for loop

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

The efficiency of looping over nested dictionaries in Python

How to make the following code more efficient? ...
1
vote
0answers
17 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
54 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
44 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
320 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
309 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
39 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
114 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
106 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
124 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
404 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
191 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
45 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: ...
3
votes
1answer
99 views

Replace for loop while with apply family function in R

I have trouble with for loop, my code runs very slowly. The thing I want to do is to use function from apply family to make my codes run faster (instead of using ...
2
votes
0answers
28 views

Merton default model with complex iterative approach

I am using Merton default model with complex iterative approach. I have already prepared my R codes but as I am quite new in R, they seem very inefficient, in sense that they runs almost 7 hours. My ...
1
vote
0answers
22 views

For loop in javascript [closed]

Whether it is Java, C#, C++ syntax for the for loop looks like that: for (int i = 1; i <= 5; i++) { // something } ...
9
votes
3answers
311 views

Optimizing “Herd Sums” problem using dynamic programming

I'm trying to solve a practice problem and all is well except for the last 2 inputs my solution is too slow. Just one loop is slowing it down I think. Herd Sums Execution Time Limit: 2 ...
3
votes
1answer
52 views

What's your opinion on this approach to creating a repetitive string in Common Lisp?

I needed to have a Lisp function that could produce a string of a certain length, created by repeated concatenations of a another string given as argument (so for example by giving 10 and "abc" i ...
6
votes
3answers
562 views

Any performance difficulties related to List<Type>?

I'm using the following structure: class Map { public List<List<Point>> points; public List<Base> bases; } ...
4
votes
1answer
62 views

Loop cleanly through different classes

If I have a number of different classes which manage certain tests. At the moment I have to launch each test individually which results in a lot of if statements. ...
5
votes
1answer
91 views

Is there a more elegant solution than this spaghetti code without completely revamping the whole page?

I use 'GROUP_CONCAT' to get comma separated lists of a person's educational background. Included in those lists are the type of degree, major, issuing establishment, and year received. ...
5
votes
1answer
115 views

Date ranges from a given start date

I'm trying to get a certain number of date ranges given a start date. Here's my code: ...
6
votes
2answers
80 views

Foreach-loop for and print commands

How can I make the following code shorter or efficient (maybe with other loops or other nice ideas), and keep the current functionality? ...
7
votes
1answer
71 views

Compute stats on two class vectors

Below is a full working code example of code which is used to compute stats on two class vectors (partitions). There are two functions: pairwise_indication and ...
4
votes
1answer
42 views

Baseline tagger

This is a baseline tagger coed I have written. How can I optimize this code? ...
7
votes
2answers
741 views

Repetitive For Loops in 2048 Game

I have the following function defined in a program that implements the 2048 game. I tried condensing the repeating part of the code into one loop containing +1 offset variables for the indices, which ...
10
votes
2answers
326 views

Using a Pythonesque range() generator function with the Java foreach loop

Now that we have the nice new foreach loop in Java, the old-style loop looks ugly be comparison. I like the way Python has a ...
7
votes
2answers
401 views

Merge some child values back into the parent multidimensional array

This is a wonky PHP function I came up with to merge some select values from child arrays into the original. It could really use some help simplifying / making it more elegant. Is there a built-in ...
10
votes
5answers
421 views

Refactoring my problem-solution to reduce complexity

I need some help refactoring my solution to the problem below: Problem Statement An Association of Computer Scientists meets on a weekly basis. There is a certain number of seats in the meeting ...
2
votes
2answers
132 views

A matrix with square diagonals and transpose being increments of other

Construct a matrix with the following property: North-west to South East diagonals are squares. Matrix[i][j] + 1 = Matrix[j][i] for each i less than j. Example of such m a matrix is ...
1
vote
1answer
74 views

Construct date sequence in Scala

I want to have a continuous date sequence like ['2014-01-01','2014-01-02', ...] Then I define a stream to do that. ...
7
votes
2answers
243 views

Pulling JSON using jQuery and manipulating the Front-end

My JavaScript is fairly new and want to learn new ways to create clean, fast code. Can you have a look at this code and guide me on how to optimise this code to improve my skills? I have provided the ...
8
votes
3answers
2k views

Brute force password-cracker

I am just coding some classic brute force password cracking program, just to improve myself. I've explained how my program works at the start of the code. Check some of those screenshots to ...