If the value of the i =1, then we are printing the current value of i. In the above example, we can see first, the statement i=1 is initialized, and then we are checking it with a while loop. In other words, the break is used to abort the current execution of the program. The break statement is used to bring the program control out of the if loop. In this, if the condition is true, then while statements are executed, if not true, another condition is checked by if loop and the statements in it are executed. The do-while loop which is not in python it can be done by the above syntax using while loop with break/if /continue statements. After one iteration, again, the test condition is checked, and this process is continued until the test condition evaluates to false. In a while loop, the test condition is checked first, and if it is true, then the block of statements inside the loop is executed. In python, while loop repeatedly executes the statements in the loop if the condition is true.
Though python cannot do it explicitly, we can do it in the following way.
The do-while loop is important because it executes at least once before the condition is checked. We are used to doing while loops in all basic languages, and we want it in python. The expression is a condition, and if the condition is true, then it is any non-true value. The above statements can be a single statement or block of statements. While loop in python has the syntax of the form: This is repeated until the condition is false. If the condition is true it jumps to do, and the statements in the loop are again executed. In a while loop, we check it at the beginning of the loop. In this syntax, the condition appears at the end of the loop, so the statements in the loop execute at least once before the condition is checked. In most of the computer programming languages, unlike while loops which test the loop condition at the top of the loop, the do-while loop plays a role of control flow statement similar to while loop, which executes the block once and repeats the execution of block based on the condition given in the while loop the end.
Web development, programming languages, Software testing & others
Start Your Free Software Development Course