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

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.

主站蜘蛛池模板: 仲巴县| 余庆县| 成安县| 连山| 湘潭县| 封丘县| 兴隆县| 宁明县| 神木县| 加查县| 汾阳市| 南漳县| 湖北省| 内江市| 贵德县| 海晏县| 伽师县| 阳曲县| 平谷区| 南投县| 余庆县| 淳安县| 金山区| 哈尔滨市| 锦州市| 祥云县| 长乐市| 甘德县| 达拉特旗| 大方县| 温宿县| 新兴县| 乌什县| 朝阳县| 土默特左旗| 平谷区| 南乐县| 天全县| 庆城县| 循化| 江孜县|