The while statement executes an embedded statement 0 or more times according to different criteria.
While statement:
while (Boolean expression) embedded statement
The while statement executes according to the following rules:
Computes a Boolean expression;
If the Boolean expression is true, control goes to the embedded statement. When (if) control reaches the end point of an embedded statement (possibly by executing a continue statement), the control goes to the beginning of the while statement;
If the Boolean expression is false, control will go to the end point of the while statement.
Within the embedded statement of the while statement, the break statement can be used to move control to the end point of the while statement (thus ending the iteration of the embedded statement), and the continue statement can be used to move control to the end point of the embedded statement (thus executing another iteration of the while statement).
If the while statement is reachable and the Boolean expression does not have a constant value of false, the embedded statement of the while statement can be reached.
If at least one of the following conditions is true, the end point of the while statement is reachable:
Using System;namespace _while_statement{class Program {public static void Main (string[] args) {int i = 0, sum = 0; while (i <=) {sum + = i++; sum + = i; i + +; } Console.WriteLine ("sum =" + sum); } }}
This article is from the "Time is the truth of the Best friend" blog, please be sure to keep this source http://joycejm.blog.51cto.com/9781632/1618939
C # BASIC Programming--while Statements