File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Problem  with for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Problem  with for loop" Watch "Problem  with for loop" New topic
Author

Problem with for loop

neelam samnani
Greenhorn

Joined: Mar 12, 2001
Posts: 8
A mock test which is cretaed by Marcus Green had asked
What will be output by the following code?
public class MyFor{
public static void main(String argv[]){
int i;
int j;
outer:
for (i=1;i <3;i++)
inner:
for(j=1; j<3; j++) {
if (j==2)
continue outer;
System.out.println("Value for i=" + i + " Value for j=" +j);
}
}

According to me answer will be "Value for i =1
Value for j=1 " , but he had answered "Value for i =1 value for j=1 And Value for i =2 , Value for j=1".

I m unable to understand that how can be value of j is remain unchanged while i's value is increasing.
I am not getting it, how it is working?
Pls. anyone can suggest me I 'll be very gratefull to them.

Neelam
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi neelam,
Basically here's what happens

Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
neelam samnani
Greenhorn

Joined: Mar 12, 2001
Posts: 8
Thanks Jane Griscti to helping me in such a good way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with for loop
 
Similar Threads
about Continue pls explain me
Marcus Green Mock #1 Q 21
Label question
Some doubt about Continue
Help with Continue ..