Saturday , December 14 2019

JAVA #15 – Nested Loop in Java with Array

 

JAVA programming language allows to use one loop inside another loop. Following section shows few examples to illustrate the concept.

Syntax:

The syntax for a nested for loop statement in C is as follows:

for ( init; condition; increment )
{
   for ( init; condition; increment )
   {
      statement(s);
   }
   statement(s);
}

 

The syntax for a nested while loop statement in C programming language is as follows:

while(condition)
{
   while(condition)
   {
      statement(s);
   }
   statement(s);
}

 

The syntax for a nested do…while loop statement in C programming language is as follows:

do
{
   statement(s);
   do
   {
      statement(s);
   }while( condition );

}while( condition );

 

A final note on loop nesting is that you can put any type of loop inside of any other type of loop. For example, a for loop can be inside a while loop or vice versa.
Original Code of Video:

package dynamicarray;
import java.util.Scanner;
public class DynamicArray {

        public static void main(String[] args) {
        String[] arrStudent = new String[5];
        Scanner objscan = new Scanner(System.in);
        
        System.out.println("Enter Student Names: ");
        for (int i = 0; i < 5; i++) { // Loop for Set Values in Array
            arrStudent[i] = objscan.nextLine();
        }
        
        System.out.println("Lists Of Student");
        for (int j = 0; j < 5; j++) { //Loor for getting values in Array
            System.out.println("Student Name: "+ arrStudent[j]);
        }
    
    }
    
}

About Faheem

Faheem
An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

JAVA #32 – Java application using SQL server (Part: 01)

  In this part we made the GUI front end of a Application.

2 comments

  1. Faheem

    Yes, I Will make it in just 1 week…

  2. Avatar

    please make some tutorials on java GUI .

Leave a Reply

Your email address will not be published.