zoukankan      html  css  js  c++  java
  • java-while循环

    while 循环 用于重复程序的一部分几次或重复执行一个代码块。如果迭代次数不固定,建议使用while循环。

    语法:

    while(condition){
        //code to be executed
    }
    //实例:
    package day02;

    public class Test12 {

        /**
         * @param args
         * @author bindu
         */
        public static void main(String[] args) {
            int i = 1;
            while (i <=10){
                System.out.println(i);
                i++;
            }
        }

    }

    无限while循环:

    package day02;
    
    public class Test12 {
    
        /**
         * @param args
         * @author bindu
         */
        public static void main(String[] args) {
            while(true){
                System.out.println("这是个死循环!");
            }
        }
    
    }

    do-while 循环:用于多次迭代程序的一部分或重复多次执行一个代码块。如果迭代次数不固定,必须至少执行一次循环,建议使用do-while 循环

    do{
      //code to be executed.
    }
    while(condition);//后置条件检查
    //实例:
    package day02;

    public class Test12 {

        /**
         * @param args
         * @author bindu
         */
        public static void main(String[] args) {
            int i =1;
            do{
                System.out.println(i);
                i++;
            }while(i<10);
        }

    }

    do-while 死循环:

    package day02;
    
    public class Test12 {
    
        /**
         * @param args
         * @author bindu
         */
        public static void main(String[] args) {
            int i =1;
            do{
                System.out.println(i);
                i++;
            }while(true);
        }
    
    }
  • 相关阅读:
    js获取下拉框的值
    根据SNP的位置从基因组提取上下游序列
    PCA分析的疑问
    os删除文件或者文件夹
    python scipy包进行GO富集分析p值计算
    生物信息等级的划分
    docker笔记
    GATK4注意事项
    centos7修改yum源为阿里镜像
    idea如何通过数据库生成实体类
  • 原文地址:https://www.cnblogs.com/1218-mzc/p/12853180.html
Copyright © 2011-2022 走看看