This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "for loop" Watch "for loop" New topic

for loop

srilavanyaa subramanian

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++)
if(k>j) break;
Burkhard Hassel
Ranch Hand

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

the magical word is indentation of your



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.
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...