Looping statements: Usage of While;do while;for

Source: Internet
Author: User

Use of While:

 Public classXunhuan { Public Static voidMain (string[] args) {//Loops                inti=10;  while(i>0){            if(i==8) {i--; Continue;//Culling} System.out.println (--i); if(i==5)                 Break;//termination}

Continue is the meaning of culling.

if (i==8) {
i--;

Continue;}

Refers to the elimination of i==8 in the circulating type

Break is the meaning of termination

if (i==5)

Break

It means that the loop stops working until five o'clock.

Do and use:

 Public classXunhuan { Public Static voidMain (string[] args) {//Loops                intI=0;        System.out.println ();  Do//Do Loop{System.out.println (i++); }         while(I<10);//End of semicolon                        }    }


The loop is started by do and ends with the last semicolon.

For use:

 Public class Xunhuan {    publicstaticvoid  main (string[] args) {// loop For                 (int m=1;m>0;m++) {         //forloop                System.out.println ("m=" +m);     }}}

Looping statements: Usage of While;do while;for

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.