Loops

There may be a situation when we need to execute a block of code several number of times, and is often referred to as a loop.
Every Language has very flexible three looping mechanisms. You can use one of the following three loops:

  • For Loop
  • While Loop
  • Do .. While Loop 


The for Loop:

A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
A for loop is useful when you know how many times a task is to be repeated.

Syntax:

for(initialization; Boolean_expression; update)
{
   //Statements
}

 Here is the flow of control in a for loop:

  • initialization
     statement executed once when beginning loop
  • Boolean
     if the test evaluates to true, the statements execute
  • update
    executes at the end of each iteration
  •  statements
    collection of statements executed each time through the loop
Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Popular Posts