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

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.

主站蜘蛛池模板: 工布江达县| 肥乡县| 罗甸县| 九台市| 寿阳县| 抚宁县| 秀山| 黔江区| 神池县| 巫溪县| 新郑市| 沧源| 平度市| 乐东| 陆川县| 滁州市| 喀喇沁旗| 砚山县| 高州市| 余姚市| 永兴县| 乐昌市| 都江堰市| 阿坝县| 昌都县| 奎屯市| 安国市| 大埔县| 庄浪县| 厦门市| 当阳市| 广州市| 禹州市| 栖霞市| 龙口市| 通辽市| 北宁市| 花莲县| 九江县| 建瓯市| 金湖县|