• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loop Problem

 
Talal Shaikh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read through the code step by step, using a variable table:


hope that helped.
 
zarina mohammad
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is how it works:
 
srinivas bolloju
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
srinivas bolloju
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.. ppl.. ur answers helped.. i understood it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic