All Questions
Tagged with loops programming-practices
7 questions
3
votes
1
answer
381
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 ...
13
votes
7
answers
12k
views
Best practice to "continue" from inside a nested loop?
Here is a simplified sample. Basically, it does checks on a string from a string list. If the check passes, it will remove that string (filterStringOut(i);), and it is no longer ...
9
votes
2
answers
11k
views
Is it good practice to use array.pop() assignment in a while loop condition?
Just saw a code snippet that used an array pop assignment in the while condition; was wondering if this is acceptable/good practice?
var arr = [0,1,2,3,4,5];
var current;
while (current = arr.pop())
{...
68
votes
17
answers
24k
views
How to write correct loops?
Most of time while writing loops I usually write wrong boundary conditions(eg: wrong outcome) or my assumptions about loop terminations are wrong(eg: infinitely running loop). Although I got my ...
1
vote
1
answer
1k
views
How to name variables without plural in a for-each loop? [closed]
How do you name loop variables when the list item is named after something without a plural? For instance (in python): [x for x in sheep]. x is not a great name, but sheep have/has no plural that ...
0
votes
1
answer
788
views
Python case statement? [duplicate]
I made a simple Python script that takes user input in order to generate a series of mathematical responses. In one part I did this:
while True:
And iterated through the loop until I used an if ...
3
votes
8
answers
8k
views
Declaring functions in order to avoid explicit nested loops
My programming professor has told me that it is a good programming practice (at least in C/C++) to declare a function with the inner loop when nesting loops (not for loops, since when, i.e. looping ...