wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Loop Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Loop Problem" Watch "Loop Problem" New topic
Author

Loop Problem

Talal Shaikh
Greenhorn

Joined: Jul 17, 2001
Posts: 13

the ans is 6 and i m confused how
Edited by Corey McGlone: Added Code Tags
[ July 23, 2002: Message edited by: Corey McGlone ]
Jon Dornback
Ranch Hand

Joined: Apr 24, 2002
Posts: 137
read through the code step by step, using a variable table:


hope that helped.


use the [CODE] tags - it makes it much easier for people to help you.
zarina mohammad
Ranch Hand

Joined: Jun 26, 2002
Posts: 104
here is how it works:
srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
hi,

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
srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
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??
zarina mohammad
Ranch Hand

Joined: Jun 26, 2002
Posts: 104
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
Talal Shaikh
Greenhorn

Joined: Jul 17, 2001
Posts: 13
Thanks.. ppl.. ur answers helped.. i understood it
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Loop Problem