Solved

Nested For Loops in Java

Posted on 2013-01-08
7
414 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now