The while statement header’s expression in the second line is n is greater than 0. Initially, n is 7, as you can see in the first line of our code. Let’s explain what happened in the above example. The following examples will help you understand the while loop better: Example 1: When the controlling expression becomes false, the loop execution ends, and the code moves on to the next statement after the loop body, if there is any. This process repeats until becomes false. After that, the system checks again, and if it turns out to be true again, it will run the body again. If the controlling expression is true, the loop body will execute. When you run a while loop, it first evaluates in Boolean. You denote them by using indentation, similar to if statements. The refers to the blocks that get executed repeatedly. It usually has one or more variables that get evaluated before beginning the loop and get modified in the loop body. Here, refers to the controlling expression.
0 Comments
Leave a Reply. |