Solved

Nested For Loops in Java

Posted on 2013-01-08
7
419 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Accepted Solution

by:
krakatoa earned 500 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

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.

861 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