1. Exam Points
Iterations:
- REPEAT n TIMES
- REPEAT UNTIL(exit condition)
Nested iterationsAnalyze algorithms represented using:
natural languageflowchartpseudocodeprogramming language- Use of iterations:
Selectthe rightalgorithmfor a given problem.Predict result or outputof given code segments.Comparetwoiteration algorithms.Represent iterationsusingflow charts.infinite loop for repeat until: when the exit condition isnever true
2. Knowledge Points
(1) Iteration
Iterationis arepeating portion of an algorithm.- Iteration
repeats a specified number of timesoruntil a given stopping condition is met. Iteration constructs(构造/结构)repeat n times- Syntax
- Example
- Syntax
repeat until(exit condition)- Syntax
- Example
- Syntax
- In
REPEAT UNTIL(condition)iteration, aninfinite loopoccurs when the ending condition willnever evaluate to true.- Example:
- Example:
- In REPEAT UNTIL(condition) iteration, if the conditional evaluates to
true initially, the loop body isnot executed at all, due to the condition being checked before the loop. - An
iterationcan benestedwithin another, you can nest any of the following loop inside another loop.- repeat n times
- repeat until(condition)
- Example of
nested iteration:
- Note:
Remember to update the loop control variableto avoid infinite loops.