Friday, August 3, 2018

Difference between For, While, and Do-While Loops in Programming

For: When you know how many times a loop should be executed then use "For loop".

While: When you feel condition is important to start a loop then use "While loop".

Do-While: When you want to execute a set of statements before condition is checked for iteration then use Do-While.

Syntax:

for(intialization;Condition;Itteration )
{
 //statements or code
}

while(Condition)
{
 //statements or code
}

do
{
 //statements or code
}while(Condition);

No comments:

Post a Comment