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
227 -
download
3
Transcript of 3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++...
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
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.
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.
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
5
[ Practice 01 logical operator ]
6
[ Explain 01 logical operator ]
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;
8
[ Practice 02 if ]
9
[ Explain 02 if ]
10
if else structure
The if else control structure allows you to specify an alternative action:
if ( condition ) action if trueelse
action if false
11
[ Practice 03 if else ]
12
[ Explain 03 if else ]
13
Syntaxswitch (expression)
{case const-expr :
statements;break;
case const-expr :statements;break;
…default statements;
break;}
switch statementswitch statement
14
[ Practice 04 switch ]
15
[ Explain 04 switch ]
0 ≦ code ≦ 4
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"
17
[ Practice 05 while ]
18
[ Explain 05 while ]
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 );
20
[ Practice 06 do while ]
21
[ Explain 06 do while ]
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;
23
[ Practice 07 for ]
24
[ Explain 07 for ]
Thank you