Solved

Nested For Loops in Java

Posted on 2013-01-08
7
417 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This is about my first experience with programming Arduino.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

770 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