0

how does this Equality Operator work?

================================================ for(int x=10; x<=40; x=x+10) { if(x == 30) { continue; } System.out.println(x); } /* Outputs 10 20 40 */ ========================================== why out come is 10,20,40 it say if x is 30, continue but x has never been 30

21st Jul 2020, 8:53 AM
jjkc
jjkc - avatar
3 odpowiedzi
+ 1
Why won't x be 30? First iteration: x = 10 Second iteration: x = 20 Third iteration: x = 30 (continues) Fourth iteration: x = 40 Loop ends
21st Jul 2020, 8:56 AM
XXX
XXX - avatar
0
i meant how can you get outcomes of 10,20 in the first place. it says if x==30. 10 == 30 is obivously not ture
21st Jul 2020, 9:12 AM
jjkc
jjkc - avatar
0
Note that the System.out.prinln(x); is outside the if block. The code means that if x == 30, then you "continue", else you show x to the screen and start again from the top with value of x = x + 10.
21st Jul 2020, 9:15 AM
XXX
XXX - avatar