Note: remember to increment i, or else the loop will continue forever.
The while loop requires relevant variables to be ready, in this example we need to define an indexing
variable, i, which we set to 1.
Output:
For Loop:
Iterating over a string (character by character):
for char in "Hello":
print(char)
Iterating using range() (for a specific number of times):
# Prints numbers from 0 up to (but not including) 5
for i in range(5):
print(i)
The range() function can take start, stop, and step arguments to control the sequence of numbers generated.