break和continue再循环for或while中用法_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > break和continue再循环for或while中用法

break和continue再循环for或while中用法

 2014/10/26 15:15:08  ewf_momo  程序员俱乐部  我要评论(0)
  • 摘要:packagecom.chaoxing.fayuan2.test;importorg.junit.Test;/***break和continue再循环for或while中用法**@author<ahref="mailto:momo_ewf@foxmail.com">莫海涌</a>*@version2014-10-26*/publicclassTestTools{@Testpublicvoidtest001(){intcount=0;for(;;){count++
  • 标签:用法 for break continue 循环
class="java">
package com.chaoxing.fayuan2.test;

import org.junit.Test;

/**
 * breakcontinue循环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);
	}
}

发表评论
用户名: 匿名