![]() In each iteration of while loop, variable sum is assigned sum + i, and the value of i is decreased by 1 until i is equal to 0. Here, the variable sum is initialized to 0 and i is initialized to 100. When you run the program, the output will be: sum = 5050 If the test expression is evaluated to false, This process goes on until the test expression is evaluated to false. ![]() then, the test expression is evaluated again.statements inside the while loop are executed.If the test expression is evaluated to true, The test expression inside the parenthesis is a Boolean expression. If you are familiar with while and do.while loops in Java, you are already familiar with these loops in Kotlin as well. You will learn about two loops while and do.while in this article with the help of examples. How about you need to print a sentence one million times? You need to use loops. Well, you can do it by using print statement 50 times (without using loops). Imagine you need to print a sentence 50 times on your screen. Loops are what makes computers interesting machines. Loop is used in programming to repeat a specific block of code until certain condition is met (test expression is false).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |