• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAVA SCJP Master Exam dowhile loop

 
Klemens Katterbauer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Milind Patil
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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 ]
 
Antonio Tercero
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Sazzad Hossain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic