cplusplus:control_structures_selection
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cplusplus:control_structures_selection [2013/02/08 02:27] – mithat | cplusplus:control_structures_selection [2017/01/31 23:57] (current) – [C++ logical operators] mithat | ||
---|---|---|---|
Line 4: | Line 4: | ||
====== Control Structures: Selection ====== | ====== Control Structures: Selection ====== | ||
- | Mithat Konar\\ | + | Mithat Konar\\ |
- | 2013-02-03 | + | |
===== Introduction ===== | ===== Introduction ===== | ||
Line 15: | Line 14: | ||
* Three kinds of control structures are used in C++ and many other languages: | * Three kinds of control structures are used in C++ and many other languages: | ||
- | * **Sequence | + | * **Sequence** |
* Statements are executed one after the other. | * Statements are executed one after the other. | ||
* This is C++'s default behavior! | * This is C++'s default behavior! | ||
Line 27: | Line 26: | ||
===== Single-entry/ | ===== Single-entry/ | ||
- | | + | * Control structures that are entered from one point and exited from one point. |
- | | + | * Connect the exit point of one control structure to entry point of the next: **control-structure stacking**. |
- | * Connect the exit point of one control structure to entry point of the next: **control-structure stacking**. | + | * Makes programs easy to build. |
- | * Makes programs easy to build. | + | |
===== Selection structures ===== | ===== Selection structures ===== | ||
- | * There are four selection structures available in C++: | + | * Four selection structures available in C++: |
* //if// | * //if// | ||
* //if/else// | * //if/else// | ||
* //nested if/else// | * //nested if/else// | ||
* //switch// | * //switch// | ||
+ | * Also has a ternary // | ||
===== if selection structure ===== | ===== if selection structure ===== | ||
Line 186: | Line 185: | ||
* ''&&'' | * ''&&'' | ||
* Takes two operands | * Takes two operands | ||
- | * Returns '' | + | * Returns '' |
* '' | * '' | ||
* Takes two operands | * Takes two operands | ||
- | * Returns '' | + | * Returns '' |
* '' | * '' | ||
* Takes one operand | * Takes one operand | ||
Line 249: | Line 248: | ||
===== Comparing characters and strings ===== | ===== Comparing characters and strings ===== | ||
+ | * [[selection_examples# | ||
* See Gaddis 4.12 (programs Pr4-20.cpp and Pr4-21.cpp). | * See Gaddis 4.12 (programs Pr4-20.cpp and Pr4-21.cpp). | ||
+ | |||
+ | ===== switch structure ===== | ||
+ | * [[selection_examples# | ||
+ | * See Gaddis 4.14 (programs Pr4-23.cpp to Pr4-27.cpp). | ||
===== The conditional operator ===== | ===== The conditional operator ===== | ||
Line 259: | Line 263: | ||
* Examples:< | * Examples:< | ||
w = x<0 ? y=10 : z=20;</ | w = x<0 ? y=10 : z=20;</ | ||
- | |||
- | ===== switch structure ===== | ||
- | * See Gaddis 4.14 (programs Pr4-23.cpp Pr4-27.cpp). | ||
===== More about blocks and scope ===== | ===== More about blocks and scope ===== | ||
- | * See Gaddis 4.15 (programs Pr4-28.cpp, Pr4-29.cpp, | + | * See Gaddis 4.15 (programs Pr4-28.cpp |
cplusplus/control_structures_selection.1360290445.txt.gz · Last modified: 2013/02/08 02:27 by mithat