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:

do {
statement(s)
} while (condition)

The loop performs the following 4 steps:


  1. Executes the statements inside the loop.

  2. Evaluate the condition.

  3. If the condition returns true, go to step 4. Otherwise, execute the next line following the end of the do while loop.

  4. 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.

x=1
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:



Other articles

Click here to Article home

MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.
 
HACKER SAFE certified sites prevent over 99.9% of hacker crime.