Java===java Basic Learning (6)---process Control, for,if,switch,continue,break

Source: Internet
Author: User

Note the point:

  • The For loop is very different from Python, note the format
  • Switch~,switch the corresponding case every time the execution has to break, because the basic not how to use switch, so as to understand.
  • To interrupt a Process Control statement, consider a multi-loop scenario, preferably with a label.
  • Continue condition satisfies, then the program to the most internal loop of the header!
//scanner text file reading and processing PackageTestbotoo;ImportJava.io.File;Importjava.io.IOException;ImportJava.io.PrintWriter;Importjava.nio.file.Paths;ImportJava.util.Scanner; Public classfile { Public Static voidMain (string[] arg){//If condition statement        intA = 10; if(A = = 10) {System.out.println ("A=" +a); }        Else if(A ==20){                                }        Else if(A = = 30){                    }        Else{                    }        //While Loop         while(A < 20) {System.out.println (a); A+=1; }                //Do while loop,System.out.println (a);  Do{a+=2;        System.out.println (a); }         while(A <30); //determining the loop for loop//declaration: A For loop is actually a simplification of the while loop, and the defined I only works in the loop body//and I can be reused in different for loops         for(inti = 1; I <=10; i++) {System.out.println ("i--" +i); }                     for(inti = 10; I >0; i--) {System.out.println ("i--" +i); }//If I have been defined outside the loop, it will also take effect outside the loop body!         inty;  for(y = ten; y <15; y++) {System.out.println (y); } System.out.println ("Value of external y" +y); //Interrupt Process Control Statement        intYear = 1; intAA = 10; Read_data://labeled, typically used on multiple loops.          while(Year <= 5) {AA+ = 1; System.out.println ("This is a value of AA" +AA); if(AA >=13) BreakRead_data; year++; System.out.println ("This is the value of year" +Year ); //This is a value of AA//This is the value of year 2//This is a value of AA//This is the value of year 3//This is a value of AA                }                //Continue usage//if the condition of the continue is satisfied, then jump to the first of the loop immediately!                 intj = 90; Scanner input=NewScanner (system.in);  while(J <100) {System.out.println ("Please enter a number greater than 0:"); intn =Input.nextint (); if(N < 0) {System.out.println ("Please re-enter"); Continue;} System.out.println ("XXXX"); if(n = = 10) Break; }        }              }    

Java===java Basic Learning (6)---process Control, for,if,switch,continue,break

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.