• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loop Problem

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
read through the code step by step, using a variable table:


hope that helped.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is how it works:
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.. ppl.. ur answers helped.. i understood it
 
reply
    Bookmark Topic Watch Topic
  • New Topic