This might be a silly question but I'm confused.
I have a for loop that excludes a given iteration (a random number). It works for any random number chosen that's greater than 0. However, if it's zero, it never does a single iteration:
int x;
for (x = 0; ((x < 2) && (x != r)); x++) {
// do something if (x != r)
}
System.out.println("X : " + x);
For the example that it's not working, r = 0. Shouldn't that mean it should skip the first iteration but does the second?
The above println yields "X : 0".
Any help? Thanks!
x != rwhile yourxis first set to 0, like yourr, causing your condition to returnfalseand not to enter the loop