• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

Nested For Loops in Java

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
Kevin_Coors
Asked:
Kevin_Coors
  • 5
  • 2
1 Solution
 
krakatoaCommented:
Kevin - we've covered this one before I am pretty sure. What difficulties have you run into now?
0
 
krakatoaCommented:
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
 
Kevin_CoorsAuthor Commented:
Hi Krakatoa

We covered nested if statements the last time

Thanks
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
krakatoaCommented:
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
 
krakatoaCommented:
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
 
krakatoaCommented:
And you didn't knock a single point off because I names the outer loop 'out' instead of 'outer' ! ;)
0
 
Kevin_CoorsAuthor Commented:
Thanks again :)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now