The while Statement by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

The while Statement

To continue executing an embedded statement as long as a certain condition holds true, the while statement is the ideal choice. Its shape is as follows:

while (condition)    embedded-statement

Just as with the if statement, the condition is a Boolean-valued expression, or to be completely accurate, something implicitly convertible to a Boolean. Once more, this means null checks or nonzero checks need to be made explicit, as opposed to C and C++, where it’s not uncommon to write code like this:

// How one would copy a string in C or C++.while (*cpy++ = *str++)    ;

Side-effecting assignment, treatment of a character as a truth value, and other wackiness with pointer arithmetic—no way in C#. (For ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required