Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Nested for loop in Java language

Posted on August 27, 2017September 14, 2019

Table of Contents

  • Nested forloop in Java language
    • Syntex
    • Flow diagram
    • Related

Nested forloop in Java language

In this tutorial, we will discuss the concept of Nested forloop in Java language.

When a forloop exists inside the body of another forloop, it is known as nested forloop in java

Syntex

for (initialization; boolean_expresion; increment or decrement){
    // statement(s) inside the body

for (initialization; boolean_expresion; increment or dicrement){

      // statement(s) inside the body

}
}

Here we can see, a for loop is inside the body another for loop

Flow diagram

Nested for loop in Java language
Explanation of outer and inner loop



Example programs     

Program 1 

This program displays square number pattern using nested whileloop

class forloop
{
public static void main(String args[])
              {

for(int x=1;x<=10; x++)   //Outer for loop
           {
System.out.println();
for(int y=1;y<=10; y++)
                           {
                                 System.out.print(y);
                            } 
                }
           }

}

When you execute the above code, it produces the following result

Nested for loop in Java language
Example



Program 2

This program displays square star pattern using nested whileloop

Nested for loop in Java language
Example



When you execute above code , it produces the folloing result

**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

Program 3

This program displays Floyd’s triangle number pattern using nested whileloop

Nested for loop in Java language
Example

When you execute above code , it produces the following result

*
**
***
****
*****
******
*******
********
*********
**********

 

Similar post

If statement in C++

Nested while loop in C Language
Nested while loop in Java
While Loop in Java      while Loop in C++     While Loop In C

Do-while Loop in Java    Do-while Loop C++     Do-while loop in C 

For Loop in C++       For Loop in C         For loop in java

If condition C++       If condition in Java   If condition in C

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes