Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.

Similar presentations


Presentation on theme: "LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals."— Presentation transcript:

1 LAB-04 IF Structure I Putu Danu Raharja raharja @kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals

2 ICS101-LAB04-Term063 2 IF Structure What is the use of IF structure? What is the type of expression we can use for condition? Can we write multiple statements in an IF construct?

3 ICS101-LAB04-Term063 3 IF Constructs (1): IF (pp. 37-38) IF (condition) THEN STATEMENT_BLOCK ENDIF When is STATEMENT_BLOCK executed? What if condition is.FALSE.?

4 ICS101-LAB04-Term063 4 IF Construct(1) YES Is Condition.TRUE. ? STATEMENT_BLOCK NO

5 ICS101-LAB04-Term063 5 IF Constructs (2): IF-ELSE (pp. 35-36) IF (condition) THEN STATEMENT_BLOCK1 ELSE STATEMENT_BLOCK2 ENDIF When is STATEMENT_BLOCK1 executed? What about STATEMENT_BLOCK2?

6 ICS101-LAB04-Term063 6 IF Constructs (2): IF-ELSE (pp. 35-36) YES Is Condition.TRUE. ? STATEMENT_BLOCK2 NO STATEMENT_BLOCK1

7 ICS101-LAB04-Term063 7 IF Constructs (3): IF-ELSEIF (pp.38-42) IF (condition_1) THEN STATEMENT_BLOCK_1 ELSEIF (condition_2) THEN STATEMENT_BLOCK_2 … ELSEIF (condition_m) THEN STATEMENT_BLOCK_M ELSE STATEMENT_BLOCK_N ENDIF When is STATEMENT_BLOCK1 executed? What about STATEMENT_BLOCK2? What about STATEMENT_BLOCK_N?

8 ICS101-LAB04-Term063 8 IF Constructs (3): IF-ELSEIF (pp.38-42) YES Condition 1.TRUE. ? NO STATEMENT BLOCK1 YES Condition 2.TRUE. ? NO STATEMENT BLOCK2 YES Condition 3.TRUE. ? NO STATEMENT BLOCK3

9 ICS101-LAB04-Term063 9 IF Constructs (4): Simple IF (pp.42-44) IF (condition) statement The same as regular IF construct but it can only execute one statement When is statement executed?

10 ICS101-LAB04-Term063 10 Exercise-1 Implement the following flow diagram using a nested IF-ELSEIF structure.

11 ICS101-LAB04-Term063 11 Exercise-2 The National Earthquake Information Center has asked you to write a program implementing the following decision table to characterize an earthquake based on its Richter scale number. Richter Scale Number (N)Characterization N < 5.0 Little or no damage 5.0 <= N < 5.5 Some damage 5.5 <= N < 6.5 Serious damage; wall may crack or fall. 6.5 <= N < 7.5 Disaster; houses and buildings may collapse higher Catastrophe; most building destroyed.

12 ICS101-LAB04-Term063 12 Exercise-3 Write a program that takes the X-Y coordinates of a point in the Cartesian plane and displays a message telling either an axis on which the point lies or the quadrant in which it is found. Y X Q-1Q-2 Q-3 Q-4 Sample lines of output: (-1.0, -2.5) is in quadrant III (0.0, 4.8) is on the Y axis (5.6, 0.0) is on the X axis (0.0, 0.0) is on the center.


Download ppt "LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals."

Similar presentations


Ads by Google