C # BASIC Programming--while Statements

Source: Internet
Author: User

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:

    • While statement contains a reachable break statement (it is used to exit the while statement). The

    • While statement is reachable and the Boolean expression does not have a constant value of true.


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.