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 in C programming language

Posted on August 30, 2017October 20, 2019

Table of Contents

  • Nested while in C programming language
    • When a while loop exists inside the body of another while loop, it is known as nested while loop in java. flow diagram
    • Syntax while(expression)    {     statements;       while(expression)          {              statements;          }    }

Nested while in C programming language

In this tutorial, we will discuss the Nested while in C programming language.

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

flow diagram

Nested while in C
Flow diagram

 

initially, the outer while evaluates the test Expression

When the condition is true, it executes the body of statements of the outer loop and the loop control move to the inner loop and statements inside the body of the inner loop is executed.This process repeats until the test expression of the inner while loop is false.

Then, when the test expression of the inner while loop is false. control exits from the inner loop and moves to outer loop again

then the loop-control evaluates the test condition of the outer while loop

The test condition of outer loop returns true, the loop control executes the body of while loop statements and move to the inner loop

Outer while loop return as false the loop control exit from the loop and goes to rest



Syntax

while(expression)
   {
    statements;

      while(expression)
         {
             statements;
         }
   }

Here we can see a while loop inside the body of another while loop.



Program 1

Nested while in C
Example

Output

0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789

  • The int variable I,j declared and initialized as zero.
  • initially, the outer while evaluate the test Expression(i<10);
  • when the test condition is true, loop move to inner loop and then checks the inner loop test-condition(j<10)
  • Here the inner while loop will be executed 10 times and print 1 2 3 4 5 6 7 8 9 during this time.
  • nest, when the test-expression of the inner loop is false, the control move to the outer loop.
  • Here the inner while loop will be executed 10 time and inner loop executes 100 times to print the above output
  • Finally, when the test expression of the outer loop is false, the loop control exits from the outer loop and goes to rest

 

Program 2

Nested while in C
Example

Output

1    2    3    4    5    6    7    8      9
2    4    6    8    10  12  14  16    18
3   6     9    12  15   18   21 24   27
4   8    12   16   20  24   28  32  36
5  10   15   20   25  30   35  40  45
6  12   18   24   30   36   42  48 54
7  14   21   28   35   42   49  56  63
8  16   24   32   40   48  56    64  72
9  18  27  36   45     54   63   72   81

Prpgram 3

Print a multiplication table using nested while loop

 

Nested while in C
Example – multiplication table
Output
Multiplication table
1*1=1
2*1=2
3*1=3
4*1=4
5*1=5
6*1=6
7*1=7
8*1=8
9*1=9
10*1=10
11*1=11
12*1=12
1*2=2
2*2=4
3*2=6
4*2=8
5*2=10
6*2=12
7*2=14
8*2=16
9*2=18
10*2=20
11*2=22
12*2=24
1*3=3
2*3=6
3*3=9
4*3=12
5*3=15
6*3=18
7*3=21
8*3=24
9*3=27
10*3=30
11*3=33
12*3=36
1*4=4
2*4=8
3*4=12
4*4=16
5*4=20
6*4=24
7*4=28
8*4=32
9*4=36
10*4=40
11*4=44
12*4=48
1*5=5
2*5=10
3*5=15
4*5=20
5*5=25
6*5=30
7*5=35
8*5=40
9*5=45
10*5=50
11*5=55
12*5=60
1*6=6
2*6=12
3*6=18
4*6=24
5*6=32
6*6=36
7*6=42
8*6=48
9*6=54
10*6=60
11*6=66
12*6=72
1*7=6
2*7=14
3*7=21
4*7=28
5*7=35
6*7=42
7*7=49
8*7=56
9*7=63
10*7=70
11*7=77
12*7=84
1*8=8
2*8=16
3*8=24
4*8=32
5*8=40
6*8=48
7*8=56
8*8=64
9*8=72
10*8=80
11*8=88
12*8=96
1*9=9
2*9=18
3*9=27
4*9=36
5*9=45
6*9=54
7*9=63
8*9=72
9*9=81
10*9=90
11*9=99
12*9=108
1*10=10
2*10=20
3*10=30
4*10=40
5*10=50
6*10=60
7*10=70
8*10=80
9*10=90
10*10=100
11*10=110
12*10=120
1*11=11
2*11=22
3*11=33
4*11=44
5*11=55
6*11=66
7*11=77
8*11=88
9*11=99
10*11=110
11*11=121
12*11=132
1*12=12
2*12=24
3*12=36
4*12=48
5*12=60
6*12=72
7*12=84
8*12=96
9*12=108
10*12=120
11*12=132
12*12=144
Related Links
 
Nested While in Python         
Nested while loop in C
Nested while in Java
Nested while 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