Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program Flow Control Selection & repetition

Similar presentations


Presentation on theme: "Program Flow Control Selection & repetition"— Presentation transcript:

1 Program Flow Control Selection & repetition
Unti-3 Program Flow Control Selection & repetition

2 In this unit we will learn the following
Understand how selection and repetition statements work Select right selection and repetition statement to control execution Solve problems using selection and repetition statements

3

4 Group Activity Build a balanced bridge using 12 sticks 100 meter tape.
Your bridge should bears heavy weights

5 Summary From the previous activity, which condition statement will fulfil the requirement

6 1. Conditional Statements

7 Conditional Statements
Conditional Statements are statements that uses relational operators to compare variables and numbers and evaluates to either true or false.

8 Relational operators

9 Activity P-72 False False Z < 500 y >= 0 True False Y != 0
watermelonSize <= appleSize True watermelonSize == appleSize y < z True False y >= x y > z False False

10 Activity P-73 Is Y less than Z? False Is Z equal to 3? True
Is X not equal to Z? True Is Y greater than or equal to 340? False Is Z less or equal to Y? True

11 2. Compound Statements

12 Compound statement

13 Compound Statements Logical operators are used to join simple conditional statements to make compound conditional statements. Each side of the logical operator gives a true or false result. The logical operator then joins the two sides to give a combined final true or false result. The logical operators are called: and, or, and not.

14 Activity P-76

15 Activity P-77 True False False False True True

16 Group Work Design a program named “grade-A” that tells the student if they deserve grade “A+” in computer science, as they should meet the following criteria If your grade is less than or equal 100 and if the grade is above 95

17

18 3. Program Flow Control Selection

19 Group Work Design a flowchart for a program that tests if the water is boiled and once it’s boiled it should warn the user.

20

21

22 Activity P-81 The following message is printed for the second case: You can now get a driving license. Go and apply at the nearest driving school. The conditional statement evaluates to true for the second case so the code below the IF is executed. The following message is printed for this case: You can now get a driving license. Go and apply at the nearest driving school. The conditional statement evaluates to true for the case; therefore, the code block below the IF is executed Nothing is printed for the first case is smaller than 18 in the first case so the conditional statement evaluates to false. The code below the IF is not executed.

23 Activity P-85 – (B)

24 Home Work Design a program that tells the driver when they have gone over the speed limit. The speed of the car should be entered by the user. If speed is more than 80 then the following message should appear “slow down.. Too fast” If speed is = 80 “good driver” If speed is less than 80 “you are so slow”


Download ppt "Program Flow Control Selection & repetition"

Similar presentations


Ads by Google