(original) C # learning Note 04--Process Control 04--cyclic 04--cyclic interrupts and infinite loops

Source: Internet
Author: User

4.4.4 Loop Interrupt
Sometimes more granular control over the processing of the loop code is required. C # provides 4 commands for this, 3 of which have already been described in other scenarios:
? break--immediately terminates the loop.
? continue--immediately terminates the current loop (resumes execution of the next loop).
? goto--can jump out of the loop to a marked position (it's best not to use the command if you want the code to be easy to read and understand).
? return--jumps out of the loop and its included functions (see Chapter 6th).
? The break command exits the loop and proceeds to the first line of code following the loop

  

4.4.5 Infinite Loop

You can define a loop that never terminates, known as an infinite loop, by writing error codes or wrong designs. For example, the following code:

 while (true) {     //

This code is also useful when using the break statement or manually using the Windows Task Manager to always exit such loops. However, when this happens occasionally, there is a problem. Consider the following loop, which is very similar to the for loop in the previous section:

int 1  while) {     if20)           Continue;     Console.WriteLine ("{0}", i++

I is incremented only after the last line of the loop has been executed, that is, after the continue statement has finished executing. However, when executing to this continue statement (at this point I is 2), the program will use the same I value for the next loop, and then test the I value, continue the loop, always go on. This freezes the application.

(original) C # learning Note 04--Process Control 04--cyclic 04--cyclic interrupts and infinite loops

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.