if((i++)%3==2) is changed to if((i++)%3==4) then it is false, here j is still 3.... then else if ((j++)%3==1) becomes true and it should break out of outer and wouldn't print anything right... but it does print some junk.... pls help also if i introduce sop(j) before else if ((j++)%3==1) to print j, it gives else without if compile error. pls help
please use the [code][/code] tags when showing code. visit <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
Joined: Jan 23, 2001
sorry people, i was thinking 3%3 is 1, silly mistake, 3%3 is 0, so that solves the issue. but 2nd issue, control stat goes through if stat and sees it is false, then goes to else if right, so why the compiler complains about else without if??
Joined: Jun 26, 2002
but 2nd issue, control stat goes through if stat and sees it is false, then goes to else if right, so why the compiler complains about else without if??
If you have more than one line of statements between "if and else if" you need to use the curly brackets to avoid such errors of "else without if" But take care that your Sop Statement is before the break statement. otherwise the statement becomes unreachable.
hope this clears your 2nd issue. -zarina
Joined: Jul 17, 2001
Thanks.. ppl.. ur answers helped.. i understood it