WHILE

\label{sec:while} \madbox

WHILE (logical_condition) { statements; } executes the statements in curly brackets while the logical_expression is true.

Warning:
Because WHILE constructs are a \madxspecial feature and not part of a full language, \madxdoes not deal gracefully with other special constructs such as MACRO or LINE when they are placed inside WHILE statement blocks: this can lead to silent and/or catastrophic errors and is due to the fact that MACRO and LINE constructs contain, either explicitly or implicitly, a closing curly bracket that unbalances the WHILE statements.

However it is possible to nest WHILE statements to at least six levels deep.

Example giving the value of the first ten factorials: \madxmp n = 1; m = 1;
while (n ¡= 10) {
  m = m * n; value, m;
  n = n + 1;
};