What is the do while loop?
Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.
What is the do while loop?
Rating:
The do while loop is used to execute the statement or a series of statements inside the loop as long as a condition remains true. The loop executes the statements before testing the condition. It ensures that the statements are executed at least once.
In the do while loop, the variable needs to be initialized and increments each time the statements are executed. When the value of variables reaches a specified value, the condition returns false and the loop ends.
The syntax of the do while loop is follows:
statement(s)
} while (condition)
The loop performs the following 4 steps:
- Executes the statements inside the loop.
- Evaluate the condition.
- If the condition returns true, go to step 4. Otherwise, execute the next line following the end of the do while loop.
- Go back to step 1.
In the following example, the do while loop is executed till the value of the variable x is less than 10.
do{
trace("X is equal to " +x); // output: 1,2,3,4,5,6,7,8,9
x++ // same as x = x + 1
}while(x<10)
Rating:
Was this information helpful?
Other articles
- What is a Math.pow method?
- What is frame-by-frame animation?
- What is the Align panel?
- What is the gotoAndPlay action?
- Tip to rotate the gradient
