While Loops
A lot of times, we don’t want code to execute just once if a condition is True. Instead, we want it to execute ‘while’ the condition is True, until the condition becomes False.
This is where while loops come in handy. They basically run the code inside them until the condition is False.
Python
while condition:
#code to run while condition is True
Here’s an example:
Python
i = 0
while i < 6:
print("I am happy!")
i = i+1
In this example, the code will print "I am happy!" 6 times.
For Loops
For loops are used for analyzing each part of a sequence of data (lists, sets, dictionaries, etc). For now, just know that it is also a type of loop used for controlling program flow. We will go over it in detail in a later section.