File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JAVA SCJP Master Exam dowhile loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JAVA SCJP Master Exam dowhile loop" Watch "JAVA SCJP Master Exam dowhile loop" New topic
Author

JAVA SCJP Master Exam dowhile loop

Klemens Katterbauer
Greenhorn

Joined: Jul 15, 2008
Posts: 8
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


Klemens Katterbauer<br />Student of Mathematics,<br />University of Vienna
Milind Patil
Greenhorn

Joined: Oct 19, 2003
Posts: 26
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 ]

Milind B. Patil - SCJP-1.4, SCWCD-5.0, SCBCD-5.0
Antonio Tercero
Ranch Hand

Joined: Jun 05, 2008
Posts: 110
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


SCJP 5, SCWCD 5
Klemens Katterbauer
Greenhorn

Joined: Jul 15, 2008
Posts: 8
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

Joined: Jul 21, 2008
Posts: 10
The reason its not compiling is because you are missing the "{" and "}" in your code.
Klemens Katterbauer
Greenhorn

Joined: Jul 15, 2008
Posts: 8
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAVA SCJP Master Exam dowhile loop
 
Similar Threads
FOR LOOP
Question about restart
Please exaplin this code
do while and while
Just a Question