Time |
S |
Nick |
Message |
00:39 |
|
|
eden joined ##friendlyjava |
02:56 |
|
|
eden joined ##friendlyjava |
10:54 |
|
|
rayyyy joined ##friendlyjava |
12:05 |
|
|
mr_lou joined ##friendlyjava |
12:05 |
|
mr_lou |
So.... for (int n=10; n>0; n--) { System.out.println(n); } |
12:06 |
|
mr_lou |
I was expect this to output 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 |
12:07 |
|
mr_lou |
Because I see "Do this as long as n is bigger than 0 - ergo when n is 1 (bigger than zero), it substracts one to n and executes the loop for 0 again. |
12:07 |
|
mr_lou |
But no. |
12:16 |
|
mr_lou |
If I want to include 0, I gotta do for (int n=10;n>=0; n--) |
12:16 |
|
mr_lou |
That doesn't make sense to my brain. |
13:09 |
|
|
rayyyy joined ##friendlyjava |
13:39 |
|
aditsu__ |
mr_lou: it executes the 3rd part after the loop body |
13:39 |
|
aditsu |
mr_lou: but you can use the arrow operator: for (int n=10; n-->0; ) {...} |
13:57 |
|
|
eden joined ##friendlyjava |
17:21 |
|
|
mr_lou joined ##friendlyjava |
20:06 |
|
|
ChanServ joined ##friendlyjava |