Nested Loop – Simple Examples

Before starting this blog we have totally know about Simple For, while, do while and condition program then we start nested loop.

So visit Chapter – 4 and Last Blog of Chapter – 5 before starting this blog.

Nested Loop is very easy thing in language.

Here, I divided nested loop in 3 parts.

  1. Simple Nested Loop

  2. Pattern Nested Loop

  3. Logical Nested Loop

 

In this blog, we will discuss on Simple Nested Loops in java program.

Some Images on Simple Nested Loop Program.

 

nested loop

 

In this image, we can see simple 5 programs.

Let’s understand the programs.

1st Step: Basic Structure of all nested programs.

for(int i=1;i<=5;i++)

{

            for(int j=1;j<=5;j++)          // Nested Loops

            {

            System.out.print(j);           // Use print() method

}

System.out.println();        // Use println() method

}

2nd Step:

This step for print i variable or j variable in System.out.print() method.

  • If program looks like 12345 or 54321, then print j variable in System.out.print(j).

  • If program looks like 11111 or 55555, then print I variable in System.out.print(i);

  • If program look like *****, then print * in System.out.print(“*”).

3rd Step: Set J Loop

  • If program looks like 12345 or 11111, then for loop like for(int j=1;j<=5;j++).

  • If program looks like 54321 or 55555, then for loop like for(int j=5;j>=1;j–).

  • If program look like *****, then for loop like for(int j=1;j<=5;j++) or for(int j=5;j>=1;j–).

4th Step: Set I Loop

  • If program look like 12345 or 11111 or *****, then for loop like for(int i=1;i<=5;i++).

  • If program look like 55555 or 54321 or *****, then for loop like for(int i=5;i>=1;i–)

 

 

These are easy steps of Simple Nested Loops.

Note:

After getting all output, you have to recheck your program and output. And Fallow the step by step loop.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

313total visits,4visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image

EmailEmail
PrintPrint