Tutorialslot.com

youtube facebook twitter gmail pinterest

Nested loops


Java allows nesting of loops,which means one loop is present inside another loop.Nesting of loops can be made possible for types of looping statements.

Syntax:

for(initialization; test; increment)
{
statements;
  for(initialization; test; increment)
  {
   statements;
   .
   .
   .
 for(initialization; test; increment)
 {
   statements;
  }
}
}

Example:
class NestedForLoop
{
   public static void main(String args[])
   {
  for(int i = 1; i <6 ; i++)
   {
   for(int j = 1; j < i+1; j++)
   {
     System.out.print(j);
   }
     System.out.println("");
   }
   }
}

Output:
1
12
123
1234
12345



Advertisement Powered By Google Adsense






IF YOU LIKE THIS TUTORIALS PLEASE SHARE

Share on whatsapp

POPULAR TAGS

Java java tutorials learn java java programming tutorial learn java online learning java professionals tutorials Multithreading Generics Object Oriented Language Methods Polymorphism Inheritance