What is the while loop?

December 29th, 2007 by uCertify Leave a reply »

The while loop is used to run a statement or a series of statements as long as a condition remains true. The loop tests the condition before the statement is executed. If the condition is true, the statement is executed. But if the condition is false, the statement is skipped and the statements following the end of the while loop is executed.

In this loop the variable needs to be initialized before the start of the loop, and the variable increments each time the statement is executed. When the value of the variable reaches a specified value, the condition returns false and the loop ends.

The syntax of the while loop is as follows:

while(condition){
statements();
}

The loop performs the following steps:

  1. Evaluate the condition.
  2. If condition returns true, go to step 3. Otherwise, execute the statements following the end of the while loop.
  3. Execute the loop statement.
  4. Go back to step 1.

In he following example, the while loop is executed till the value of the variable x is less than 10.

stop();
x=1
while(x<10){
trace(”X is equal to ” +x); // output: 1,2,3,4,5,6,7,8,9
x++ // same as x = x + 1
}

Click here to get free 9A0-058 Adobe Flash CS3 ACE exam practice questions. Get certified in first attempt download 9A0-311 - Macromedia Flash Professional simulation.
Like this article? Share it with others
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.