while
loop)for
loop)Nature of while
Loop:
while condition:
statements
How while
Loop Works:
Infinite Loops:
Nature of for
Loop:
for
statement designed for sequences of data items.for variable in [val1, val2, ...]:
statements
Using the range Function:
range
Function:Controlling Loop Iterations with User Input:
range()
. Generating Descending Sequences with range
:
range(10, 0, -1)
generates numbers from 10 to 1.accumulator
variable that maintains the running total.+=
: x += 5
means x = x + 5
-=
: y -= 2
means y = y - 2
*=
: z *= 10
means z = z * 10
/=
, %=
, //=
, **=
.while
loop can ensure only valid data is accepted:range
function within for loops.