Loops are a type of control flow structure, in which, a series of statements may be executed repeatedly until some condition is met.
-1
votes
1answer
26 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 ...
1
vote
0answers
19 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
24 views
3
votes
2answers
144 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
39 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
39 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:
...
-1
votes
0answers
14 views
Java - Scanner is being ignored inside while loop but not elsewhere [closed]
I'm in a bit of a pickle with my code as I can't understand why a particular user prompt is being ignored, when the exact same code is being used successfully elsewhere.
This is an example of where ...
0
votes
2answers
42 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
198 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
69 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
22 views
1
vote
3answers
62 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
50 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
107 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
42 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
291 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
33 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
54 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
76 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
59 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
66 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
84 views
8
votes
2answers
145 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
112 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, ...
3
votes
3answers
92 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
18 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 (...
4
votes
2answers
77 views
Picking the top 5 results for each individual
For loops are the devil. I can't see a way to speed this up with apply or other more speedy functions though...
...
5
votes
1answer
60 views
ExcelVBA loop exports data from spreadsheet to table within Excel
I want to nest a for loop to cycle through the Range.Value but ("B4") throws me off and this can't be avoided. I was considering using an array to do this but ...
1
vote
1answer
84 views
Many CRUD operations for a list of technicians' shifts
The following code snippet is causing me a performance problem in my application. The first 5 db queries are not high time consuming, the real problem lays on the foreach loop. I considered to use ...
1
vote
3answers
68 views
4
votes
2answers
118 views
Balancing the server load
I've created a program that will take, a bunch of numbers from a range of 1 - 255, and then put them into 3 different strings(servers) equally. It does this by ...
5
votes
1answer
50 views
Concatenate data files into master document
Here is code I wrote to concatenate data files into master file. Once the data to be pasted into the master sheet exceeds the number of rows left in the master sheet, the program will create a new ...
1
vote
2answers
60 views
Checking if an element exists in an array efficiently and return it
I am writing a function for my node/angular app that will prompt the user with a random question that he was not asked before.
To achieve this I wrote this function:
...
7
votes
3answers
103 views
Searching the same values in an array
If I am not mistaken, this method has a complexity \$O(N^2)\$:
...
3
votes
4answers
111 views
Determining whether a loop iterated at least one element in generator function
I have a case in which I need to determine whether a for loop yielded at least one element:
...
4
votes
1answer
104 views
Powershell zip subfolders recursively, conditionally
This is a progression of the script I posted here: Zip the contents of subfolders, conditionally
It does this:
Determines all subfolders recursively
Checks each subfolder for files older than 31 ...
12
votes
2answers
669 views
Loop round and remove the consonants
The main objective of this code is that you must accept an input from the user and loop and remove the consonants and vice versa and display the new word.
I know there is a easier way of doing it, ...
20
votes
8answers
2k views
Writing nested for loops to produce certain output
My task:
Write nested for loops to produce the following output with each line
48 characters wide:
...
3
votes
1answer
86 views
Fetching settings for batches of wafers using loops
I have this code below that needs to query multiple database tables.
...
7
votes
2answers
140 views
99 times drunk on Java
This is a rags-to-riches attempt from this question, based on the popular 99 Bottles of Beer, by (lightly) using Java 8's stream-based processing.
Any room for improvement in terms of readability? I ...
1
vote
2answers
46 views
2 ways to print a half-pyramid
I wrote this bit of C that prints a half-pyramid,
*
**
***
****
Here's the main body:
...
10
votes
3answers
381 views
Beer song excercise
I'm reading the book Head First Java and got an assignment to re-create the 99 Bottles of Beer song according to those lyrics found in the URL. I've had to do this with a Java while loop.
...
1
vote
1answer
47 views
Listing EC2 instances
I've got this massive nested for loop with a few if and else statements in nodeJs. The output of all of this is just string which is combined from different values out of JSon object. What I want to ...
1
vote
1answer
25 views
Looping in Scheme
(define loop
(lambda (x proc)
(when (not (= x 0))
(eval proc)
(loop (- x 1) proc))))
Is this the best way to create a loop function in Scheme?
2
votes
1answer
112 views
Cross validation of gradient boosting machines
I am fairly new to Python. I implemented a short cross-validation tool for gradient boosting methods.
...
2
votes
1answer
81 views
Java loop extracting month and year between two dates
I have a ContratMercan with 2 Timestamps containing start and ...
1
vote
0answers
48 views
Looping through JSON object with nested for loops
I've written a function that loops though all of the accounts, properties, views, and filters - each 'level' requires another for loop. I'm working with the Google ...