While Loop
The While loop keeps repeating an action until an association condition returns False. It means that when a while loop started, it checks the condition, if it’s true then it executes the block of statements and then rechecks the condition and executes until the condition gets False.
Syntax
initialisation;
while(condition)
{
block of statement;
increment/decrement;
}
Sample Program
Output
Sample program-2
Output
Nested While Loop
When we insert a while loop under a while loop then, it is called Nested While Loop.
Syntax
Sample Program
Output
Do While Loop
The Do-While Loop is similar to while Loop, but the condition is checked after the loop body is executed. This ensures that the loop body is run at least once.
Syntax
initialisation
do
{
block of statements;
increment/decrement;
}while(condition);
Sample Program
Output
Nested Do While Loop
When we insert a Do-while loop under a Do-while loop then, it is called Nested-Do-While loop.
Syntax
initialisation
do
{
block of statements;
increment/decrement;
do
{
block of statements;
increment/decrement;
}while(condition);
}while(condition);
Sample Program
Output
- What is On-Page Optimization and Off-page Optimization - March 14, 2024
- [SOLVED] Flutter : PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null) - December 7, 2021
- [Solved] Flutter : Error: The getter ‘subhead’ isn’t defined for the class ‘TextTheme’ from package:flutter/src/material/text_theme.dart’ – searchable_dropdown - December 6, 2021