Skip to main content

Questions tagged [loops]

A **loop** is a sequence of statements which is specified once but which may be carried out several times in succession.

1 vote
1 answer
487 views

Efficient way to skip ticks/frames in a loop?

So: main does a loop, and every iteration it increments a tick by one For example, say it were in python because that's easy to write: def main(): tick = 0 while True: tick += 1 ...
ThorSummoner's user avatar
7 votes
3 answers
9k views

Communication between microservices - distinguishing internal calls safely

I am rearchitecturing and rewriting my monolithic BaaS solution into microservices regarding to scalability and single responsibility rules. Due to the internal dependencies, services are placed on ...
denolk's user avatar
  • 173
-10 votes
1 answer
2k views

Java: Why's this For-Loop thousands of times slower?

So I have a simple method I'm calling millions of times a second, and I noticed that it was taking 16% of all processing time!! The offensive routine is as follows: public void placeHolder(){ ...
thebest108's user avatar
15 votes
7 answers
3k views

Should <= and >= be avoided when using integers, such as in a For loop? [closed]

I have explained to my students that equal-to testing is not reliable for float variables, but is fine for integers. The textbook I am using said that it is easier to read > and < than >= and <=....
user avatar
1 vote
4 answers
7k views

Nested For Loops JavaScript

I have an app which gets data from the database (MongoDB) in JSON format. The returned data contains nested arrays and I want to access the values in the nested arrays. The returned JSON format looks ...
Lorenzo von Matterhorn's user avatar
2 votes
1 answer
309 views

printing in methods vs printing in the main/driver class

I'm fairly new to programming and am currently creating a blackjack game in Java. I've progressed quite well, although could use some pointers with regards to the best way to implement a method. At ...
Konzy262's user avatar
  • 123
0 votes
2 answers
254 views

Do some built-in functions loop behind the scenes?

I mostly code in C# & VB, but I think this question is pretty universal. I try to limit loops to increase performance. For instance, string functions that split the string into an array, or do a ...
JMcD's user avatar
  • 19
2 votes
2 answers
169 views

Load to list in one loop and then process list in another or do it all at once

I have a dataset full of rows that I must initialize into myclass and then process. I am currently looping through each row in the dataset, initializing a new instance of myclass, then adding that ...
S1r-Lanzelot's user avatar
-2 votes
3 answers
8k views

Best way to handle variables used in a for loop? [duplicate]

From previous experience, I had always thought that, if you are going to use variables inside of a for loop, it was much better to declare them outside of the loop vs. inside the loop itself. I ...
user25839's user avatar
23 votes
8 answers
5k views

At what point is it taboo to have loops within loops?

Just curious. The most I have ever had was a for loop within a for loop, because after reading this from Linus Torvalds: Tabs are 8 characters, and thus indentations are also 8 characters. There ...
Anon's user avatar
  • 3,613
27 votes
2 answers
47k views

Filtering foreach loops with a where condition vs continue guard clauses

I've seen some programmers use this: foreach (var item in items) { if (item.Field != null) continue; if (item.State != ItemStates.Deleted) continue; // code } instead ...
Paprik's user avatar
  • 399
130 votes
11 answers
38k views

Is there anything that can be done with recursion that can't be done with loops?

There are times where using recursion is better than using a loop, and times where using a loop is better than using recursion. Choosing the "right" one can save resources and/or result in fewer lines ...
Pikamander2's user avatar
  • 1,269
-1 votes
1 answer
194 views

eradicating the array = loop mindset [closed]

I have noticed a common issue in code reviews, that takes this form: // "arr" is an array for (i = 0; i < arr.length; ++i) { if (i == 3) { // do something with arr[i] } if (i ==...
JoelFan's user avatar
  • 7,091
6 votes
2 answers
2k views

Is using for loop syntax for a "with(variable)" block an anti-pattern?

I fooled around with for-loops, remembered the with keyword from delphi and came up with following pattern (defined as a live template in IntelliJ IDEA): for ($TYPE$ $VAR$ = $VALUE$; $VAR$ != null; $...
Binkan Salaryman's user avatar
2 votes
2 answers
150 views

Did labelled loops pre-date for loops?

Was the first implementation of looping control flow effectively the goto (or something like a labelled JMP in assembler) or was there another syntactic construction? for (für) was introduced in ...
52d6c6af's user avatar
  • 730

15 30 50 per page
1
3 4
5
6 7
11