Do While Loop:

Do while loop is used to repeat a block of statements. It is an exit control loop so, it checks the condition after executing of the statement. Do while loop consists of Test Expression and Update Expression. Since it is an exit control loop, it executes the program for at least 1 time, before execution ends.

Test Expression tests the condition and executes the statement only if the condition is satisfied.

Update Expression updates the variable loop variable by increasing or decreasing it by some value.

Example:

// initialisation expression 
int i = 1; 
do { 

    // Print the statement 
    System.out.println("Hello"); 

    // update expression 
    i++; 
} 
// test expression 
while (i < 6); 

Enter fullscreen mode Exit fullscreen mode

The above code prints Hello 5 times.

原文链接:Do While Loop:

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容