Table of Contents:
for i in l
- Repeat body for each item in listl
.while condition
- Repeat body tillcondition
becomesFalse
.- In some situations, when a condition is met, we might want to exit the loop then and there.
eg:
- Scan for the list.
- When value is found, stop scanning.
- Return the position of value, if not found then return -1.
break
exists the loop when called.- Skips looping elements after break is called.
else
can be attached for awhile
or even afor
.
for i in l:
...
else:
...
while Condition:
...
else:
...