CyberSlug Rules!

Beginner Programming CMPS060

Prof. Paulo Franca

Home

Syllabus

Login

Objects

Download

Staff only

while

repeat a statement while an expression is true: 

while ( <expression> )
{
<statement>
}

<statement> is repeated while the result of <expression> is non zero (true)

Notes:

  • <statement> may be a compound;
  • if <expression> is zero at start, <statement> is not executed;
  • <statement> must include means of changing the value of expression or other means of escaping the loop;
  • beware of infinite loop;

Example: