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
1answer
53 views

Load title from database based on member country

As tim suggested, some changes to the database was necessary. I have posed an improved version of this question at Get title from database based on member country. I have the following database: ...
4
votes
2answers
95 views

Optimise nested loops used to compare champions which have abilities which have effects

I'm creating a counter picker for a game called League of Legends, and for this I need to compare effects of abilities, which each champion has. For this I'm using 4 lists of champions, the ...
3
votes
0answers
46 views

Optimising looping through large data set and updating database

I have a database table storing information about documents (MigrationMaster). There is another table with security information on these (DocumentSecurity). There are 4 steps I can see that I need to ...
3
votes
1answer
46 views

Extracting coordinates file that are inside a bounding box

I'm scanning a CSV file to see which values fit inside of a given box. The CSV file has X and Y coordinates, and the arguments to the function are the perimeters of a box (i.e, top, bottom, left side, ...
2
votes
0answers
36 views

Grammar for loops and equality

I used lemon parser to write rules for while and == . The == rule looks like: ...
0
votes
1answer
59 views

Shell command line program

I have refactored a for loop into a function. I'm still a beginner at using C utility functions such as strtok, ...
0
votes
1answer
52 views

Exponentiation using while loop in Python

I could not think of any better way to raise to power, except this, but how do I refactor it? I should only use while loop, not for loop, not x**y. I shall not use pow(x,y) ...
4
votes
4answers
90 views

Advent of Code Day 6: toggling lights in a grid with Powershell

I am using the "Advent of Code" series to help with my PowerShell education. The Day 6 puzzle has a 1000 × 1000 grid of lights. After processing instructions to turn on, turn off, or toggle rectangles ...
7
votes
1answer
963 views

Drawing the flag of Liberia

I am working on this assignment to draw the flag of Liberia for my essentials of computer programming class. I finished it but had extra time to kill and noticed that a couple similar blocks of ...
-3
votes
1answer
31 views

this procedure basically gets a sentence of the user and the splits it up into its position values and writes them to a file

this program does work entirely without any errors appearing however I would like to shorten it down to make it more reliable and neat ...
3
votes
0answers
105 views

Google CodeJam 2016 - Ruby - Counting Sheep

https://code.google.com/codejam/contest/6254486/dashboard#s=p0&a=0 I just wrote a small Ruby class to solve the first of the challenges in the G CodeJam. I am not strong at this sort thing so ...
10
votes
5answers
821 views

Finding two consecutive triangular numbers with a given target sum

I need to speed up this code so it can handle inputs in the thousands. It adds triangular numbers to a list based on input n, then it loops through to find if any two consecutive numbers squared in ...
-2
votes
1answer
99 views

3 exams, 20 students: calculating the per-student average score [closed]

I'm a little curious... I have to work on a program in which a student takes 3 exams and the average is taken from the 3 exams that a student takes. It then goes into a form of a table, where one ...
1
vote
1answer
47 views

Methods to check form validity and to count invalid form fields

I have two these methods. Their loops are pretty similar. I'd like to refactor it to avoid duplicate nested loops. How could I do that? ...
3
votes
0answers
105 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
4
votes
2answers
70 views

Product of 2 numbers equals sum of numbers between them

Problem: Find all the pairs (a, b) whose product is equal to the sum of all numbers in the sequence [1..n] excluding both a and b. I have made code for one program and need refactoring for code to ...
1
vote
1answer
47 views

Nested loop to transform MongoDB results

I have the following structure returned from MongoDB: ...
5
votes
3answers
159 views

OnStartApplicationsCommand function

The foreach loop seems ridiculously lengthy and I am trying to get rid of it altogether is possible. But there are a lot of things happening in there which I need ...
3
votes
1answer
53 views

Learning nested for loops in Python with Pig Latin translator

I've been trying to learn Python for a bit now. I've taken a few courses, but I've found that I've been going about them wrong and had allowed them to "hold my hand" too much. I'm trying to build ...
0
votes
2answers
46 views
1
vote
1answer
150 views

Calculating all possible Knight turns (Chess)

I'm creating a console application that takes as input starting column and starting row, also the ending column and the ending row and it's going to output all the possible way's to get to that point ...
1
vote
0answers
47 views

CasperJS continue equivalent inside for loop with casper.then

CasperJS doesn't allow continue statement inside a casper.then functions. This was my solution but I'm not happy about it. Is ...
-3
votes
1answer
78 views

Four-function calculator with a text menu

This code works but I don't know if I am doing this correctly. I want to have a do-while loop for the menu and app. How could I ...
2
votes
1answer
48 views

Nested loops - Random Forest, multiple parameters

I'm writing a code which task is to grow Random Forest trees based on multiple parameters. In short: Firstly, I declare a data frame in which model parameters and some stats will be saved. Secondly, ...
2
votes
1answer
55 views
3
votes
2answers
194 views

“Guess my Number” game in Python (2.7.9)

First time posting to Code Review. Just looking to get some advice on how I can write better code. I found the following exercise for a "Guess my Number" game on DaniWeb, but the linked source code ...
3
votes
0answers
73 views

Basic game engine: timer, FPS and logic loop

I'm creating a simple Java game engine (just for fun). The idea is to create a basic framework for developing any kind of 2D game, an abstract engine that does the hard work. Would you like to review ...
0
votes
2answers
46 views

Partitioning an array of objects into four arrays by one attribute

I have an array of API objects, below is an example of one object: ...
0
votes
2answers
56 views

PHP alternative syntax confusion

Newbie to PHP. Trying to output the results of an array inside a foreach loop. I have got the following code but I cannot understand what to do with it next. Mainly; Where/how do I start and end ...
4
votes
3answers
207 views

Using Enum to Handle String literals

I have a java component that was using a lot of string literals that I need to make comparisons on and return booleans based on these comparisons. In order to make the code more robust I externalized ...
4
votes
3answers
78 views

Extracting sleep quality scores from periodic readings

How can I optimize the next function to work faster? The function must prepare a list to put in a CSV file. The list must contain values of average percentage of sleep per minute counted from ...
3
votes
1answer
47 views

Simple load testing script in bash

Here's the code ...
1
vote
3answers
65 views

Reading denormalized data using a stateful loop body

I'm reading denormalized data with a SqlDataReader, the data has this form: ...
1
vote
1answer
55 views

Transforming a list into a dictionary

I have a simple list and want to filter it by a specific key. But I guess my for loop solution is not an efficient way. I'm searching an other way or one best practice. ...
3
votes
1answer
116 views

Tail-recursive call vs looping for a Poker app

I'm developing a Poker app. It is almost done, and I'm looking for improvement. One of the things I wonder is whether I should change how I perform iterations. I currently iterate by using ...
0
votes
1answer
46 views

Better way to loop through current and next element [closed]

Let's assume I want to iterate over a list and want to check the current item against the next item. The way I do it for now is like this: ...
1
vote
1answer
54 views

Return Object[] while connecting to DB once

I have written this code according to my requirements. But after finishing the code, it looks like there are too many loops. I have reduced it as much as I can. Can you find any improvements that I ...
11
votes
4answers
1k views

Python sprinting game using strings, loops and statements

Here is my code for a sprinting game in Python. You have to tap the 'a' and 'd' keys as fast as you can to run 100 meters. Any improvements? ...
4
votes
3answers
326 views

'Retry' mechanism with callback

We've had a situation whereby we have to cater for certain exceptions and retry a particular method whenever these exceptions occur. This is required in various parts of the system. In addition, we ...
-3
votes
2answers
38 views

Display calendar using a loop

Desired output: Can I get an shorter version of this code? My instructor just wants me to figure it out my self. ...
5
votes
1answer
61 views

Creating cover traffic by calling random urls - Javascript loop to decrement float

This is a for-loop which runs once for each step with i>1 and maybe for ...
1
vote
1answer
84 views

Computing the distance and weight matrix of a graph

I would like to create an igraph object. First, I set up the size of igraph object — n, m, then create a random matrix. As a result matrix ...
2
votes
0answers
92 views

Convert A for loop in R to apply function

My goal is to iterate over a datamatrix, calculate mean, standard error of the mean, and then have a bar plot representing the 2 groups of my data matrix in R. My code below works as a for loop. ...
2
votes
1answer
69 views

Generating calendar months for a datepicker

I got a problem I'm finding pretty hard to solve. I'm trying to generate calendar months for a datepicker but at only 12 months I see a perf of around ~4-7ms. This doesn't sound like a problem but it ...
1
vote
1answer
111 views

Getting employee details according to the role

Here is my issue.I have two classes: ...
9
votes
2answers
228 views

Swift replacement for C's for-loop

I recently wrote an entry on my blog regarding unit testing using prime numbers as an example. When I wrote the entry, I wrote my code keeping in minding that proposal SE-0007 has been accepted for ...
6
votes
2answers
44 views

Creating a list of new areas for patches of conserved land within a watershed

I'm writing code to create a list of new areas for patches of conserved land within a watershed based on the current size distribution of conserved land patches that are in the watershed now. I'm ...
7
votes
1answer
263 views

Path finding algorithm using recursion in Python

Here is a code I developed some time ago. I wonder if there is anything I can do to improve it. It works for non-loopy mazes which was already my goal. In the maze defined, ...
4
votes
3answers
112 views

Loops to merge documents and renumber pages

I have a for loop implementation for merging documents and page re-numbering. But since I am modifying the collection while iterating, I suspect that the code might ...
0
votes
1answer
20 views

Python 3 - better iterate over list or over range of indexes? [closed]

Using Python 3 (3.5 to be exact), I want to iterate over a two-dimensional list. I have the choice to either iterate over the list content directly, or to iterate over the list indexes (...