nested for Loop in Java

nested for Loop in Java


Posted in : Core Java Posted on : October 7, 2010 at 5:41 PM Comments : [ 0 ]

In this tutorial, We will discuss for use and implementation of nested for loop in java.

nested for Loop in Java

In this tutorial, We will discuss for use and implementation of nested for loop in java. The nested for loop is the type of  looping construct when we use for loop inside for loop. All the statements which has to be executed written in the for block. we can use for loop inside another for loop is called nested for loop.

Syntax of nested for loop-

for( initialization; termination; increment)
        {
       for( initialization; termination; increment){
        .........
        }

}

In the given example we will  print a triangle as-

Code:

package com.devmanuals2;

public class NestedForLoop {

	public static void main(String[] args) {
		int j;
		System.out.println("Example of nested for loop");
		for (int i = 0; i < 5; i++) {
			for (j = 0; j < i; j++) {
				System.out.print(i);

			}
			System.out.println();

		}

	}

}

Output:

Example of nested for loop

1

22

333

4444

Download The Code.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics