cplusplus:control_structures_repetition_in_algorithms
This is an old revision of the document!
Control Structures: Repetition in algorithms
Mithat Konar
2013-02-03
Introduction
- Input validation
- Sentinel/flag control
- Menus
- Counter control
- Iterators
Input validation
- Do not continue with program until user has entered valid data.
- Pseudo code:
Get input value from user While input value is not valid Get input value from user
Sentinel/flag control
- Sentinel:
- Value(s) that indicate(s) a special condition; “special value”
- Flag:
- Sometimes used as a synonym for sentinel
- Sometimes means a sentinel that is a Boolean value
Sentinel-controlled repetition
- Sentinel-controlled repetition:
- Repeat as long as a sentinel condition is not matched
- Pseudo code:
While input value is not -999 do something
- Input validation might be considered a special case of sentinel controlled repetition.
Menus
- Repeating menus can be implemented with sentinel control.
- Pseudo code:
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
Counter control
TODO
Iterators
TODO
cplusplus/control_structures_repetition_in_algorithms.1361319407.txt.gz · Last modified: 2013/02/20 00:16 by mithat