Ad

What Terminates A While Loop When Its Expression Is A Conditional Expression

- 1 answer

the title says it all

in a loop likes this written in C

while(first_statement ? second_statement : third_statement)

how can a loop like this be terminated?

Ad

Answer

A loop using while(statement1 ? statement2 : statement3) will be terminated if at a time when the condition is tested, either of the following apply:

  • statement1 evaluates to non-zero and statement2 evaluates to zero
  • statement1 evaluates to zero and statement3 evaluates to zero

(It can of course also be terminated by things such as a break statement or a return from the function that contains it.)

Ad
source: stackoverflow.com
Ad