Several common cyclic codes for C # language

Source: Internet
Author: User

One, while loop
1. Code format
while (loop condition)
{
Loop body
}
2. If the loop condition is true, the loop body is executed
After the loop body is executed, when the condition is judged to be true,
If true, the loop body is executed so that it ends when judged false

Second, do andloop

1. Code format
Do
{
Loop body
}
while (cyclic condition);
2. Execute the loop body first and then determine if the loop condition satisfies
If satisfied, the loop body is executed again until the condition does not meet the end

Third, forLoop

1. Code format
for (expression 1; loop condition); Expression 2
{
Loop body
}
2. Run an expression 1
Determines whether the loop condition is true and, if true, executes the loop body
After execution, the expression 2 is run, and then the loop condition is judged
Until the loop condition is False end

Iv. breakand Continue

1. Break
End Current Loop
2. Continue
End the current value loop and proceed directly to the next numeric operation Loop

V.foreach Loop

1. Can only be used to iterate over an array or collection
2. Code format:
foreach (data type variable in array or collection)
{
Loop body
}
3. The Foreach loop is also called a read-only loop, and the collection or array cannot be changed in the loop body.

Several common cyclic codes for C # language

Related Article

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.