class="java"> package com.chaoxing.fayuan2.test; import org.junit.Test; /** * break和continue再循环for或while中用法 * * @author <a href="mailto:momo_ewf@foxmail.com">莫海涌</a> * @version 2014-10-26 */ public class TestTools { @Test public void test001() { int count = 0; for (;;) { count++; System.out.println(count); if (count >= 10) { break; } } } @Test public void test002() { int count = 0; do { count++; System.out.println(count); if (count >= 10) { break; } } while (true); } @Test public void test003() { int count = 1; do { switch (count) { case 10: break; default: count++; System.out.println(count); } if (count >= 10) { break; } } while (true); } @Test public void test004() { int count = 1; lableA: do { switch (count) { case 2: break lableA; default: count++; System.out.println(count); } } while (true); } @Test public void test005() { int count = 1; lableA: for (;;) { switch (count) { case 2: break lableA; default: count++; System.out.println(count); } } } @Test public void test006() { int count = 1; lableA: for (;;) { count++; System.out.println(count); for (;;) { if (count == 2) { // continue lableA; // break lableA; // break; continue; } } } } @Test public void test007() { int count = 1; do { count++; if (count == 2) { continue; } System.out.println(count); } while (true); } }