Control Structures: Repetition in Algorithms
- Counter control
- Sentinel/flag control
- Input validation
- “Repeat something a known number of times.”
- Uses a counter variable.
Set counter's initial value While counter has not yet exceeded the STOP_VALUE Do something Increment counter
- Value(s) that indicate(s) a special condition — a “special value”
- “Repeat as long as a sentinel condition is not matched.”
Get value While value is not SENTINEL value Do something Get value
- Input validation might be considered a special case of sentinel controlled repetition.
- Sometimes used as a synonym for sentinel
- Sometimes means a sentinel that is a Boolean value
- “Prevent moving to next section until user has entered valid data.”
Get input value from user While input value is not valid Get input value from user
- Repeating menus can be implemented with sentinel control.
Show menu Get menu choice from user While input value is not QUIT value Process the menu choice Show menu Get menu choice from user
- Do something to every item in a collection.
For each item in collection Do something with or to the item
cplusplus/control_structures_repetition_in_algorithms.txt · Last modified: 2020/02/10 21:45 by mithat