3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++...
-
Upload
christine-johns -
Category
Documents
-
view
239 -
download
3
Transcript of 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++...
![Page 1: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/1.jpg)
33..ㅎㅎ
•logical operator•if•if else•switch•while•do while•for
Third step for Learning C++ Programming
Third step for Learning C++ Programming
Repetition Control Structures
![Page 2: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/2.jpg)
2
&& Operator (logical AND opterator)
&& is a boolean operator, so the value of an expression is true or false.
( cond1 && cond2 )
is true only if both cond1 and cond2 are true.
![Page 3: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/3.jpg)
3
|| Operator (logical OR operator)
|| is a boolean operator, so the value of an expression is true or false.
( cond1 || cond2 )
is true if either of cond1 or cond2 is true.
![Page 4: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/4.jpg)
4
The ! operator (logical NOT operator)
The ! operator is a unary boolean operatorunary means it has only 1 operand.
! negates it's operand.! means "not".
(! condition)is true only when condition is false
![Page 5: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/5.jpg)
5
[ Practice 01 logical operator ]
![Page 6: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/6.jpg)
6
[ Explain 01 logical operator ]
![Page 7: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/7.jpg)
7
if structure
The if control structure allows us
to state that an action (sequence
of statements) should happen
only when some condition is true:
if (condition )action;
![Page 8: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/8.jpg)
8
[ Practice 02 if ]
![Page 9: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/9.jpg)
9
[ Explain 02 if ]
![Page 10: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/10.jpg)
10
if else structure
The if else control structure allows you to specify an alternative action:
if ( condition ) action if trueelse
action if false
![Page 11: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/11.jpg)
11
[ Practice 03 if else ]
![Page 12: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/12.jpg)
12
[ Explain 03 if else ]
![Page 13: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/13.jpg)
13
Syntaxswitch (expression)
{case const-expr :
statements;break;
case const-expr :statements;break;
…default statements;
break;}
switch statementswitch statement
![Page 14: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/14.jpg)
14
[ Practice 04 switch ]
![Page 15: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/15.jpg)
15
[ Explain 04 switch ]
0 ≦ code ≦ 4
![Page 16: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/16.jpg)
16
while Control Structurewhile Control Structure
The while control structure supports repetition - the same statement (or compound statement) is repeated until the condition is false.
while (condition)do something;
•the the inside is called
inside is called
•the "body of the loop"
the "body of the loop"
![Page 17: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/17.jpg)
17
[ Practice 05 while ]
![Page 18: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/18.jpg)
18
[ Explain 05 while ]
![Page 19: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/19.jpg)
19
do whiledo while
The do while control structure also provides repetition, this time the condition is at the bottom of the loop.the body is always executed at least once
do somestuff ;
while ( condition );
![Page 20: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/20.jpg)
20
[ Practice 06 do while ]
![Page 21: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/21.jpg)
21
[ Explain 06 do while ]
![Page 22: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/22.jpg)
22
for loops
The for control structure is often used for loops that involve counting.
You can write any for loop as a while (and any while as a for).
for (initialization; condition; update)do something;
![Page 23: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/23.jpg)
23
[ Practice 07 for ]
![Page 24: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/24.jpg)
24
[ Explain 07 for ]
![Page 25: 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.](https://reader036.fdocuments.net/reader036/viewer/2022062720/56649f0e5503460f94c22f68/html5/thumbnails/25.jpg)
Thank you