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

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.

主站蜘蛛池模板: 鹤庆县| 铜川市| 盐津县| 深州市| 安乡县| 榆林市| 武汉市| 开化县| 株洲县| 赫章县| 常山县| 开原市| 蓝田县| 呼伦贝尔市| 林州市| 肥乡县| 华安县| 亳州市| 临高县| 汝州市| 延边| 广州市| 怀化市| 泰宁县| 柘荣县| 岑巩县| 邻水| 呼伦贝尔市| 阿拉善右旗| 辽宁省| 克拉玛依市| 金寨县| 桂林市| 普格县| 临猗县| 长泰县| 铜鼓县| 潼南县| 遵义市| 南安市| 邵阳县|