Python Loops
Also know as Iteration. In Python we can identify two main types of loops.
While Loop
As long as the value in the variable"i" is less than 10 (condition) it prints the value of "i".
There's no auto increment in while loop.
As you can identify in the abve code, identation(spacing) and : (colon) is important when using loops.
for Loop
It iterates over the string value and assign each charachter to the the variable "i".
As you can identify in the abve code, identation(spacing) and : (colon) is important when using loops.
for Loop with "range" function.
The return values of "range" function by default starts from 0.
By deafault the increment is one(1).
Sructure
range(Start, Stop, Step):
Values from 1 (start) to 10 (stop) and skip values by 2 (step).
To reverse the values(descending order), use negative numbers for the step value.
Example
range(1 , 10 , -1):
Output will numbers from 10 to 1(descending order).