Loop Problem
posted 23 years ago
the ans is 6 and i m confused how
Edited by Corey McGlone: Added Code Tags
[ July 23, 2002: Message edited by: Corey McGlone ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
the ans is 6 and i m confused how
Edited by Corey McGlone: Added Code Tags
[ July 23, 2002: Message edited by: Corey McGlone ]
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
read through the code step by step, using a variable table:
hope that helped.
hope that helped.
use the [CODE] tags - it makes it much easier for people to help you.
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
srinivas bolloju
Ranch Hand
Posts: 112
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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??
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??
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">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
zarina mohammad
Ranch Hand
Posts: 104
posted 23 years ago
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
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
Posts: 13
posted 23 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks.. ppl.. ur answers helped.. i understood it 

| Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






