JavaSE之简单循环结构

**

  • 循环结构
  • while语句:判断boolean表达式的值,如果为true,则执行下面逻辑处理,如果为false,则跳出循环结构。
  • break语句:在while循环中,可直接用break语句跳出整个循环,不再执行后续循环。
    */
 1 public class User {
 2     public static void main(String[] args) {
 3         //1、简单循环
 4         int scont =0;
 5         for (int i=0;i<=100;i++){
 6             scont += i;
 7         }
 8         System.out.println(scont);
 9      }
10 }
 1  //2、do while循环
 2 
 3 public class User {
 4     public static void main(String[] args) {
 5        int i = 0;
 6         do {
 7             System.out.println("无聊"+i);
 8             i++;
 9         }while (i<10);
10     }
11 }
 1  3、for循环
 2 
 3 public class User {
 4     public static void main(String[] args) {
 5        for (int i=0;i<9;i++){
 6             if (i==4){
 7                 continue;    //continue:取消本次打印,但不影响下一次
 8             }
 9             System.out.println(i);
10         }
11     }
12 }

 

posted @ 2021-04-16 20:44  夜景&  阅读(57)  评论(0)    收藏  举报