PYTHON Theory
Loops
Loops are used to executed a set of statements repeatedly until a particlar condition is satisfied.
PYTHON supports four loop types:
1. Entry controlled loop(for loop, while loop)
2. Exit controlled loop(do-while loop )
3. Exit controlled loop(foreach loop)
For Loop
For Loop
A loop is used for execute a sequence of statements multiple times until a given condition returns false.
Syntax |
---|
for(<variable_name> in <sequence>) { #Block of code to be executed Example: for i in range(1,5): print(i) } |
While Loop
While Loop
A loop is used for executing a block of statements repeatedly until a given condition is true. It has three arguments, namely, initialization, test-condition, and increment/decrement variable.
Syntax |
---|
initialization statement; while (test-condition): { #Block of code to be executed increment/decrement statement; } |