My study Record-java SE 04

Source: Internet
Author: User

(iii) Process Statements

3. Control cycle Structure

1) break

* In the switch statement, use to terminate a sequence of statements.

* For exiting a loop, use the break statement to rush through the exit loop, ignoring any other statements and loop condition tests in the loop body.

* When a break statement is encountered in a loop, the loop is terminated and program control is restarted in the statement following the Loop.

Instance:

 packageday4;Importjava.util.Scanner; public classexam_1 { public Static voidmain (string[] Args) {//TODO auto-generated Method StubScanner input =NewScanner (system.in); intnum = 1; intcut; System.out.println ("enter a number of 1-100"); Cut=Input.nextint (); while(num<=100) {System.out.println (num); if(num==Cut) {               break; } num++; }  }}

2) continue

* Discard subsequent non-executed program code in this Cycle.

Instance:

Using the If method:

With continue

3) return

*  the return in the loop is used in cases where the loop Body contains a switch statement.

The code that encounters return in the loop and terminates at return will not Execute.

Where to terminate the loop, use return.

My Learning Record-java SE

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.