Loops

14 1 3
                                        


In python there are 2 types of loop, 

While Loop 

and

For loop


WHILE LOOP

This is a loop, that will continue to loop until the condition is false.

that means.

if the 5>0 is true it will run 

but when 

its 0>0 its false it will stop.

until the condition is true the while loop will continue loop.

eg:- 


lets say:- 

stamina=5  #varibale stamina with 5 as value

while stamina>0:  #condition stating the down below code will run until stamina is 0

print("+1 stats and training")  #literally printing

stamina= stamina -1  #decreases per code run in loop, 5=4=3=2=1=0 0 will stop the code


FOR LOOP

it is a loop that is mostly use for iteration of items. 

lets say

you have numbers up to 5. 

you need to 1-5 then we can use for loop

eg:-

for i in range(5): #it starts from 0 remember that, 0-4

print(i)


MORE EG:-

let say you have list of items that you want to declare or show/

animes=["Naruto", "Umamusume", "Code Geass", "Onepiece", "Bleach"]  #list of animes

for anime in animes:                                 #you can use i instead of anime: - for i in animes:

print(anime)  #literally prinitng

PYTHON JOURNEY BY BEGINNERWhere stories live. Discover now