25
3 3 . . ㅎㅎ •logical operator •if •if else •switch •while •do while •for Third step for Learning C++ Programming Repetition Control Structures

3.3.3.3. ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures

Embed Size (px)

Citation preview

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Thank you