Nested Loops in Java

Nested loop is nothing but loop inside a loop. A very basic example for a nested loop is shown below.

public class NestedLoopDemo {

	public static void main(String[] args) {

		for(int i = 3; i>0;  i--)
		{
			for(int j = 0; j<2; j++)
			{
				System.out.println("i :: "+i+" j :: "+j);
			}
		}
	}
}
Try It

The output is :

i :: 3  j :: 0

i :: 3  j :: 1

i :: 2  j :: 0

i :: 2  j :: 1

i :: 1  j :: 0

i :: 1  j :: 1


Next > < Prev
Scroll to Top