Martin Gerard wrote:Whats the difference between = and =>
Can anybody help please?
int aNum = 3;
Its just the behaviour of the operators that is puzzling me.
"<" is "Less Than"
"<=" is "Less Than or Equal"
So, if aNum is 5, then your first loop counts: 0, 1, 2, 3, 4. Your second loop counts: 0, 1, 2, 3, 4, 5.
Note that your first loop iterates 5 times through the loop but your second one iterates 6 times through the loop because it starts at zero.
The first loop is the preferred usage in Java unless there is a specific need to do it another way. Note that writing a loop any other way but the first example will slow down the comprehension of the human reader because they will have to take the time to understand why it was written differently.
Syntax errors like that aren't serious; they won't get past the compiler. The following loops and selection statements contain errors, but not all of them, Some are more serious than others.All the errors should be obvious; I have not obfuscated anything.
Carey Brown wrote:(...)
The first loop is the preferred usage in Java unless there is a specific need to do it another way.
If I use the index as an index into some structure, I use 0 and <. But when used as a counter, I go from 1 to the end <=, since I like to count from 1 to say 10, and not from 0 to 9. But that is of course very personal.
There are three kinds of actuaries: those who can count, and those who can't.