Loop statements are used to execute certain set of statements again and again in a program.
Different types of Loops:
1. While loop: While loop is used to execute the statements within it till the condition is true.
Syntax:
while(condition)
{
Statements;
}
2. Do while loop: Do while loop is also used to execute the statements till the condition is true but in this loop, statements will be executed first after that the condition will be checked. It will execute the statements at least one time even if the condition is false at the beginning.
Syntax:
do
{
statements;
}
While (condition);
3. For loop : In For loop, all the three parts of the loop that is initialization, condition and iteration are all written in a single statement. Initialization means initial value given to variable, condition upto which loop will execute and iteration is increment or decrement of value of variable.
Syntax:
For(initialization; condition; iteration)
{
Statements;
}
What are Loop statements or Iteration Statements?
More Questions
- What are the different types of Conditional Statements?
- What do you mean by Conditional statements or Control Statements?
- What is a Recursive function?
- What are the different types of Branching Statements?
- What are the features (characteristics) of Java?
- What are the different storage classes available in C?
- What are the Logical Operators?
- What are the Branching Statements?