The while statement executes embedded statements if, and as long as, a condition is true.
while ( condition ) {
... statements ...
}
Do While condition
... statements ...
Loop
while ( condition ) {
... statements ...
}
|
|
C# |
VB |
JScript |
A while statement is executed as follows:
- The condition is evaluated.
- If the condition is true, the embedded statements are executed.
- Thereafter, control is passed back to the beginning of the while statement, and the processs is repeated as long as the condition is true.
- When the condition returns false, the loop ends and control is passed to the statement after the while block.
The below example demonstrates use of a while loop to repeatedly render an HTML block, increasing the font size with each pass thru the loop.
Show me
Below are links to further code examples that illustrate using the while loop in ASP.NET web forms.