?
Solved

Nested For Loops in Java

Posted on 2013-01-08
7
Medium Priority
?
423 Views
Last Modified: 2013-01-08
Hello

I am taking a shot in the dark here.

Could anyone explain in simple terms how a nested for Loop works please?

I have just got used to working with single looping structures and I have been introduced to nested loops and I just cannot seem to get my head around them.

Thanks
0
Comment
Question by:Kevin_Coors
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 16

Expert Comment

by:krakatoa
ID: 38755997
Kevin - we've covered this one before I am pretty sure. What difficulties have you run into now?
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 38756023
In 'short' - a loop completes whatever task you set it, up to its iteration limit. If it is enclosed by another loop, - (nesting) - that outer loop takes another iteration, and the inner loop is repeated.
0
 

Author Comment

by:Kevin_Coors
ID: 38756024
Hi Krakatoa

We covered nested if statements the last time

Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Accepted Solution

by:
krakatoa earned 2000 total points
ID: 38756063
class Loop{

public static void loop(){
	for (int a=0;a<10;a++){
       	    System.out.println("Out loop value is --->"+a);
       		for (int b=0;b<20;b++){
             			System.out.println("Inner loop value is ---> "+b );
       		 }
	}
}

public static void main(String[] args){loop();}

}

Open in new window

0
 
LVL 16

Expert Comment

by:krakatoa
ID: 38756074
We covered nested if statements the last time

*Did* you mean nested, then? If so, there's a short and v simple one above. Let us know if this is not what you had in mind. There is plenty of help here if it isn't.
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 38756729
And you didn't knock a single point off because I names the outer loop 'out' instead of 'outer' ! ;)
0
 

Author Comment

by:Kevin_Coors
ID: 38756747
Thanks again :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question