cplusplus:control_structures_repetition_in_algorithms
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
cplusplus:control_structures_repetition_in_algorithms [2013/06/30 09:14] – [Input validation] mithat | cplusplus:control_structures_repetition_in_algorithms [2019/02/11 16:40] – [Sentinel-controlled repetition] mithat | ||
---|---|---|---|
Line 2: | Line 2: | ||
~~NOTOC~~ | ~~NOTOC~~ | ||
- | ====== Control Structures: Repetition in algorithms | + | ====== Control Structures: Repetition in Algorithms |
Mithat Konar\\ | Mithat Konar\\ | ||
- | 2013-02-28 | + | 2019-02-11 |
===== Introduction ===== | ===== Introduction ===== | ||
- | * Input validation | ||
- | * Sentinel/ | ||
* Counter control | * Counter control | ||
+ | * Sentinel/ | ||
+ | * Input validation | ||
+ | * Menus | ||
* Iterators | * Iterators | ||
- | ===== Input validation | + | ===== Counter-controlled repetition |
- | * "Block moving to next section until user has entered valid data." | + | * "Repeat something a known number of times." |
- | * Pseudo code:< | + | * Uses a counter variable. |
- | While input value is not valid | + | * Pseudocode:< |
- | | + | While counter has not yet exceeded the STOP_VALUE |
+ | | ||
+ | Increment counter</ | ||
- | ===== Sentinel/flag control ===== | + | ===== Sentinel control ===== |
* **Sentinel**: | * **Sentinel**: | ||
- | * Value(s) that indicate(s) a special condition; " | + | * Value(s) that indicate(s) a special condition |
- | * **Flag**: | + | |
- | * Sometimes used as a synonym for sentinel | + | |
- | * Sometimes means a sentinel that is a Boolean value | + | |
===== Sentinel-controlled repetition ===== | ===== Sentinel-controlled repetition ===== | ||
* " | * " | ||
- | * Pseudo code:< | + | * Pseudocode:< |
- | While input value is not SENTINEL value | + | While value is not SENTINEL value |
Do something | Do something | ||
- | Get input value</ | + | Get value</ |
* Input validation might be considered a special case of sentinel controlled repetition. | * Input validation might be considered a special case of sentinel controlled repetition. | ||
+ | * **Flag**: | ||
+ | * Sometimes used as a synonym for sentinel | ||
+ | * Sometimes means a sentinel that is a Boolean value | ||
+ | |||
+ | ===== Input validation ===== | ||
+ | * " | ||
+ | * Pseudocode:< | ||
+ | While input value is not valid | ||
+ | Get input value from user</ | ||
===== Menus ===== | ===== Menus ===== | ||
* Repeating menus can be implemented with sentinel control. | * Repeating menus can be implemented with sentinel control. | ||
- | * Pseudo code:< | + | * Pseudocode:< |
Get menu choice from user | Get menu choice from user | ||
While input value is not QUIT value | While input value is not QUIT value | ||
Line 44: | Line 53: | ||
Show menu | Show menu | ||
Get menu choice from user</ | Get menu choice from user</ | ||
- | |||
- | ===== Counter-controlled repetition ===== | ||
- | * " | ||
- | * Uses a counter variable. | ||
- | * Pseudo code:< | ||
- | While counter has not yet exceeded the STOP_VALUE | ||
- | Do something | ||
- | Increment counter</ | ||
- | |||
===== Iterators ===== | ===== Iterators ===== | ||
* Do something to every item in a collection. | * Do something to every item in a collection. | ||
- | * Pseudo code:< | + | * Pseudocode:< |
Do something with or to the item</ | Do something with or to the item</ | ||
cplusplus/control_structures_repetition_in_algorithms.txt · Last modified: 2020/02/10 21:45 by mithat