Loops - BenWare-FED/Python GitHub Wiki

Steps:

  1. Initialization

  2. Condition Check

  3. Updation

  4. Body of the loop

[] = stuff inside is included

() = stuff inside is not included

Syntax

initialization

while(condition_check):

  updation             quick note, updation and body can flip based on the circumstance

  body_of_the_loop

Steps example

  1. Declare a variable num_1 and assign 1

  2. While num_1 is less than or equal to 10, repeat the following steps

         display the value in num_1
    
         increment num_1 by 1
    

Code example

num_1 = 1

while(num_1 <= 10):

 print(num_1)

 num_1 = num_1 + 1      can also be written as num_1 += 1

Types of Loops

while loop: Keeps going while a condition is met.

for loop: Position index called i.