All Questions
4
questions
-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 ...
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 ...
2
votes
2
answers
3k
views
Is there a difference between declaring variables outside or inside a loop? [closed]
Is there any difference if I were to write something like this:
int row,col;
for(row = 0; row < data.length; row++){
for(col = 0; col < data[row].length;col++){
//do ...
16
votes
5
answers
41k
views
Does it make a difference if I declare variables inside or outside a loop in Java?
Does it make a difference if I declare variables inside or outside a loop in Java?
Is this
for(int i = 0; i < 1000; i++) {
int temp = doSomething();
someMethod(temp);
}
equal to this (with ...