Java Foundation _break and Contiune usage

Source: Internet
Author: User

To put it simply, for example, a program like this:
For (...) {
...
Continue/break;
...
}
System.out.prinln ("a");

Continue means to execute "for (...)" immediately. This line of code, break means to immediately execute "SYSTEM.OUT.PRINLN (" a ");" This line of code.

Run break directly ends the for loop
Run continue directly to the next loop

The following code example
Package Java_test;public class Breaktest {public static void main (String args[]) {System.out.println ("loop does not start"); System.out.println ("Start test continue now"); for (int i = 0; i < 3; i++) {System.out.println ("start" + i + "secondary for Loop"); if (i = = 1) {continue;} System.out.println ("Look at continue after the execution here?" ");} SYSTEM.OUT.PRINTLN ("Continue test completed \n***********************"); System.out.println ("Start Test break Now"), for (int i = 0; i < 3; i++) {System.out.println ("start" + i + "secondary for Loop"); if (i = = 1) {bre AK;} System.out.println ("Look at the break after it's done here?") ");} SYSTEM.OUT.PRINTLN ("Break test completed \n***********************");}}

Operation Result:

Loop does not start

Start testing Continue now

Start the No. 0 time for Loop

Have you seen continue here?

Start the 1th time for loop

Start the 2nd time for loop

Have you seen continue here?

Continue test complete.

***********************

Start Test break now

Start the No. 0 time for Loop

See if it's done here after break?

Start the 1th time for loop

Break Test complete

***********************

 

Java Foundation _break and Contiune usage

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.