官术网_书友最值得收藏!

The while loop

The while loop repeats a block, while its conditional expression returns true:

    while (condition) { 
        //code 
    } 

There is also a do... while loop that repeats blocks as long as a conditional expression is returning true:

    do { 
        //code 
    } while (condition)  

Kotlin, as opposed to Java, can use variables declared inside the do... while loop as a condition:

    do { 
        var found = false 
        //.. 
    } while (found) 

The main difference between the while and do... while loops is when a conditional expression is evaluated. A while loop checks the condition before code execution and if it is not true, the code won't be executed. On the other hand, a do... while loop first executes the body of the loop, and then evaluates the conditional expression, so the body will always execute at least once. If this expression is true, the loop will repeat. Otherwise, the loop terminates.

主站蜘蛛池模板: 黔江区| 东方市| 通河县| 施甸县| 兴安县| 慈溪市| 拜城县| 衡阳县| 镇江市| 汉沽区| 潮州市| 榆社县| 玛曲县| 阿巴嘎旗| 永宁县| 济源市| 嵩明县| 专栏| 巩义市| 贵南县| 泗洪县| 东乡县| 榆林市| 石家庄市| 紫金县| 开封市| 大关县| 拉萨市| 新巴尔虎右旗| 五家渠市| 乌兰浩特市| 济宁市| 宜阳县| 安顺市| 乌什县| 余庆县| 丹东市| 南宫市| 巴彦淖尔市| 莒南县| 夏邑县|