06 While循环详解

While 循环

package com.zhan.base_2;

public class Test06_While {
    public static void main(String[] args) {
        int i=0;
        int n=0;
        int sum=0;
        // 正常循环,一般情况下
        //输出 1+2+3+···+100总和
        while (i<10){
            i++;
            System.out.println(i);
        }
        // 正常循环,一般情况下
        while (n<=100){
            sum+=n;
            n++;
        }
        System.out.println(sum);

        //死循环,这里是伪代码来着,,特殊情况下
        while(true){
            // 等待客户端连接
            //定时检查
            // ········
        }
    }
}
posted @ 2023-01-22 13:40  被占用的小海海  阅读(17)  评论(0编辑  收藏  举报