Questions tagged [loops]
A **loop** is a sequence of statements which is specified once but which may be carried out several times in succession.
153 questions
1 vote
1 answer
216 views
Should I separate special cases from for loop deliberately, or let a for loop handles special cases naturally?
Suppose I need to find the last selected index of options according to last selected contents, eg: options : A,B,C,D,E ,last selected option: C, so the last selected index is 2. There is a special ...
-3 votes
1 answer
91 views
Declarative name for function with multi-purpose-loop from broken-up monolithic function [closed]
I'm currently in the process of reworking a monolithic function. My first step is finding blocks of code that can be extracted into their own "sub"-methods for ease of readability & ...
-1 votes
2 answers
5k views
Loop pattern for batch data processing
When processing data sets in batches I usually can think of the following three implementations. Which one do you consider better than the other and why? Notes: The implementation is in C# but the ...
4 votes
2 answers
160 views
Separation of data retrieval and processing in loops?
Often I need to get some data and process it in some way. For example getting a list of customers from an API and assemble some summary data on them. As an example, getting : api_result = api.request(...
-5 votes
1 answer
1k views
How do I manage multiple nested for-loops without using multiple variables? [closed]
If I have code that looks like this: int i; void functionA (){ for (i=0; i<10; i++){ functionB(); } } void functionB (){ for (i=0; i<20; i++){ doSomething(); } } ...
24 votes
9 answers
9k views
Declaring that a function never returns
If I have a function that never returns (it contains an infinite loop) how do I declare/communicate that it will never return to the user of the function? The user does not see the source code, only ...
3 votes
1 answer
433 views
What is the expected performance of While loops using `array.pop()` assignment vs other methods
Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
-4 votes
1 answer
166 views
Is there any formula or trick to count how many times a statement inside a nested loop gets executed?
I am modifying a software which is for trash collection. While reading the code, I asked myself is there any formula or trick to quickly calculate the number of time the statement gets executed inside ...