• 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

JAVA SCJP Master Exam dowhile loop

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have a question regarding the following loop construct


I know that System.out.println("I is " + I) belongs to the do while loop, but why do i need the additional while statement. I tried it out in eclipse and it didn't let me compile.

Thanks for comments
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you take a look at the construct, after formatting, it is like this.



It compiles and output blank.
[ July 21, 2008: Message edited by: Milind Patil ]
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your're code is correct and it compiles fine:
It defines 2 loops :


System.out.println("I is "+I) belongs to the while() loop which is nested inside a do .. while() loop
 
Klemens Katterbauer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, yes that's also what i thought about but



produces the output "I is 1 " and according to your code, this can never happen because the while loop fails every time.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason its not compiling is because you are missing the "{" and "}" in your code.
 
Klemens Katterbauer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To Sazzad Hoss

The code compiles perfectly well, but the suggested structure of the previous comments don't match the real outcome.

That's the problem
reply
    Bookmark Topic Watch Topic
  • New Topic