C#for (;;) What is the meaning?

Source: Internet
Author: User

One, the normal for loop we have been exposed to a lot, as below, we all understand

           int [] tt = {1,2,3,4,5,6  };              for (int16; i++)            {                Console.WriteLine (tt[i]);            }    

Two, but for (;;) What does it actually mean?

Meaning: For parentheses, the content before the first semicolon is executed before the first loop, and the contents before the second semicolon are judged before each execution (if the value of the expression is true, then the loop body is executed, and if False, then the loop body is jumped out)

Third, do you think it is so common to write about it? Well, let's do some expansion, the following code

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacew{classProgram {Static voidMain (string[] args) {            intt2 =0; intT1 =0;  for(Demo.first (refT1); Demo.scend (T1,refT2);            ) {Console.WriteLine (T2); }        }    }     Public classDemo { Public Static intj =5;  Public Static BOOLFirst (ref intT1) {T1=1; return false; }         Public Static BOOLScend (intT1,ref intT2) {            if(J >0) {J= J-T1; T2=J; return true; }            Else            {                return false; }        }    }}

Three, in the above code we see for (Demo.first (); Demo.scend (1,ref te); ) is to call two methods in a semicolon, is not the same as usual use?? Then why do you use it this way? We are based on for (;;) Meaning to parse.

1, the content before the first semicolon is executed before the first loop, and the first semicolon does not determine true and false, so the definition returns false and does not jump out of the loop

2, the second semicolon before the content is to be judged before each execution (if the value of the expression is true, then the loop body, if false, then jump out of the loop body)

C#for (;;) What does that mean?

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.