The while Loop Statement

The while loop repeats a statement or compound statement again and again, here referred to as loop body, as long as its associate loop condition, consisting of a Boolean expression, is true (see Syntax Box 9.1). When the loop condition is false while being evaluated, flow of control moves to the line immediately following the while loop.

Syntax Box 9.1 The while-Loop

while (<Loop_condition>)


<Loop_condition>::= <Boolean_expression>

<Loop_body>::= <Statement>;
           ::= <Compound_statement>


  • The loop body is repeated as long as <Loop_condition> is true.

The keyword while is suitably chosen; we can even use it to describe the semantics of the while loop in plain English:

While (the ...

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.