Statements: while loop

The while loop iteration statement lets you repeat a nested statement.

Syntax

while(condition)statement

Discussion

The while loop statement executes the nested statement repeatedly as long as the condition evaluates to the boolean value true. The condition is evaluated at the begin of every iteration. To execute multiple statements within the loop, you can group those together within a block statement. For example:

// Find the first visible view
var Core::View view = FindNextView( null, Core::ViewState[ Visible ]);

// Hide all text views existing within the current GUI component
while ( view != null )
{
  var Views::Text textView = (Views::Text)view;

  // Is this a text view?
  if ( textView != null )
    textView.Visible = false;

  // Continue with the next view
  view = FindNextView( view, Core::ViewState[ Visible ]);
}

The while statement can be combined with the statements break and continue. break causes the loop to exit immediately passing the control to the next statement following while. In this case, the condition is not evaluated. When continue statement is executed inside a loop, the control jumps to the beginning of the loop for next iteration, skipping over all following statements inside the body of loop for the current iteration. For example:

while ( inx++ < count )
{
  var int32 v = Array[ inx ];

  if ( v > 10 )
    continue;

  if ( !v )
    break;

  sum += math_pow( 2, v );
}