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 while loop in Java language

Posted on August 27, 2017September 14, 2019

Nested whileloop in Java language

In this tutorial, we will discuss the Nested while loop in java language.

Nested whileloop

When a whileloop exists inside the body of another whileloop, it is known as nested whileloop in Java.

Flow diagram

Nested while loop
flow diagram



Syntex

while(expression)
   {
    statements;

      while(expression)
         {
             statements;
         }
   }

Here we can see, a whileloop is inside the body another whileloop.


Example in nested while loop

Program 1

The program displays square star pattern using nested whileloop

Nested while loop
Example


When you execute above code , it produces the folloing result

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

program 2

The program displays Floyd’s triangle star pattern using nested whileloop.

Nested while loop
Program

When you execute above code , it produces the folloing result

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


Program 3

The program displays multiplication table using nested while loop.

class nestedwhileloop
{
public static void main (String args[])
{
int i=1, j=1;
System.out.println(“Tables”);
while(i<=2)
{
while(j<=12)
{
System.out.println(i+”*”+j+”=”+(i*j));
j++;
}
i++;
System.out.println(“”);
j=1;

}
}

}

When you execute above code , it produces the folloing result.

Nested while loop
Program

Related Links

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