1/11
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
loop
repeat a block of code multiple times without writing it again
process multiple items
repeat same task
unknown repetitions
why are loops useful?
condition-controlled loop
count-controlled loop
types of repetition structure
condition-controlled loop (while)
loop continues as long as the condition remains true.
count-controlled loop (for)
repeats a specific number of times
while loop
repeatedly executes a target statement as long as a given condition is true
for loop
runs a block of code a specific number of times or goes through every item in a sequence eq. string
break
continue
pass
loop control statements
break
immediately ends the loop, even if the condition/range isn't finished
continue
skips the current step and moves to the next one
pass
does nothing; used as a placeholder when you don't want any action yet
choose the right loop type
avoid infinite loops
keep it simple
best practices for loops