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

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes