[Java Basics] Loop structure 1

Source: Internet
Author: User

[Java Basics] Loop structure 1

Loop structure: For loop, while loop, Do_while loop, enhanced for loop

/**file path: G:\JavaByHands\ Loop statement file name: Whiletest.java written: 2016/6/7 Author: Zheng Write a description: While the Do while code example*/ Public classwhiletest{ Public Static voidMain (string[] args) {//Initial conditions        inti = 0; //into the loop, while the loop first judges the re-operation condition         while(I < 5) {            //Output StatementSYSTEM.OUT.PRINTLN (i + "< 5")); //Operating conditionsi + +;                } System.out.println (i); // Do While//Initialize Condition        intj = 0; //go to loop do While loop first operation condition again Judge         Do{System.out.println (J+ "<5"); J++; }         while(J < 5);            System.out.println (j); }}
/**file path: G:\JavaByHands\ Loop statement file name: Fortest.java Write Time: 2016/6/7 Author: Zheng Write a description: For loop code example*/ Public classfortest{ Public Static voidMain (string[] args) {//the most basic for loop         for(inti = 0;i < 5; i + +) {System.out.println (i); }                //Loop Nesting//First Floor         for(intj = 0;j < 5; J + +) {            //Second Floor             for(intK = 0;k < 3; K + +) {System.out.println (The value of "J" is: "+j); System.out.println (The value of "K" is: "+k); System.out.println ("-------------"); }        }            }}

[Java Basics] Loop structure 1

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.