package com.chongrui.test;

/*
*Break 是直接中止循环
*continue 只能运用在for while do ...while循环语句当中,用于让程序直接跳过后面的语句,进行下一次的循环
*return语句比较
* 输出10以内的全部奇数
*
* */


public class test {

public static void main(String[] args) {
test test1 = new test ();
test1.testBreak1();

test1.testContinue1();

//test1.testBreak2();
// test1.testContinue2();
}

/**
* 测试continue
* continue用来结束本次循环
*/
public void testContinue1() {
System.out.println("--------测试continue-------");
for (int i = 1; i <= 5; i++) {
if (i == 3) continue; //像输出结果就不会有3
System.out.println("i=" + i);
}
}

/**
* break用来结束整个循环体
*/
public void testBreak1(){
System.out.println("--------测试break1-------");
for(int i=0;i<=5;i++){
if(i==3)
break;
System.out.println("i=" + i);




}


}


}

 

 

--------测试break1-------
i=0
i=1
i=2
--------测试continue-------
i=1
i=2
i=4
i=5

相关文章:

  • 2021-04-07
  • 2021-12-02
  • 2022-12-23
  • 2021-12-26
  • 2022-01-11
  • 2022-01-09
  • 2021-12-10
猜你喜欢
  • 2021-08-02
  • 2021-12-02
  • 2021-09-26
  • 2022-01-29
  • 2022-01-17
  • 2022-12-23
  • 2021-05-09
相关资源
相似解决方案