While loop While loops are used when a block of code needs to be executed as long as the specific condition is True. Syntax: while condition: // code to be executed Before we see the examples of while loop, Below are the couple of points to remember. If the condition is not satisfied (or False) on the first instance, code inside the loop will not be executed at all. If the condition is satisfied (or True) for every iteration, Loop will run infinitely. Let's have a look at the simple example. In the above example, Line - 1: Creating or Initializing variable to use in the condition or loop. Line - 2: while 'condition', We are using condition 'i < 10'. Loop would repeat as long as the value of 'i' is less than 10. Line - 3: print statement to print the value of 'i'. This is usually replaced with the required action in the program. Line - 4: Incrementing the value of 'i' by '1'. Incrementing, Decrementing or Amending the...
Code with PR - Technical tips on coding and more...