All Questions
Tagged with loops conditions
4
questions
2
votes
2
answers
175
views
Should special case be inside or outside the for loop here?
For example, suppose I have 2 arrays:
let arr1=[5,2,1];
let arr2=["abcde","ab","a"];
my work is simple : to check if length of strings in arr2 are larger than corresponding element with same index ...
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())
{...
2
votes
1
answer
898
views
Proper way to refactor multiple if based conditions [duplicate]
I took over a large legacy code base. It has a code like this:
if ($route == 'login' || $route == 'logout' || $route == 'forgot-password') {
return;
}
if ($loggedInUser == false && $...
7
votes
5
answers
18k
views
Is doing an assignment inside a condition considered a code smell?
Many times I have to write a loop that requires initialization of a loop condition, and an update every time the loop executes. Here's one example:
List<String> currentStrings = ...