my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "for loop" Watch "for loop" New topic
Author

for loop

srilavanyaa subramanian
Greenhorn

Joined: May 30, 2006
Posts: 26
could any one explain me the logic behind this code....i just want to know how the nested loop is wrking
public static void main(String args[])
{
int c = 0;
A: for(int i = 0; i < 2; i++)
{
B: for(int j = 0; j < 2; j++)
{
C: for(int k = 0; k < 3; k++)
{
c++;
if(k>j) break;
}
}
}
System.out.println(c);
}
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

the magical word is indentation of your




OK?

Bu.


all events occur in real time
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
To understand such loops insert System.out.println statements at interesting places in your program. Print out the variables at those stages.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: for loop
 
Similar Threads
Question from jqplus
Confused with pre and Post increment please help ..
confusing for Loop.
Flow Control -JQ+
I am not getting the required output...