When you do this: for(i=0;i<n;i++);
you are essentially doing this: for(i=0;i<n;i++) {}
. This translates to a loop with no body.
This also happens for while
loops: while(..);{<Foo>}
. The extra ;
will make execute only once.
The same goes for if
statements. Doing if(a==b);{<Foo>}
will still execute <Foo>
for the same reason. If a == b
, then, the empty statement will be taken into consideration. Afterwards, <Foo>
will be executed. This can give the wrong impression that Java will treat a false
as a true
since if a != b
, then, <Foo>
would still be executed.