Presentation is loading. Please wait.

Presentation is loading. Please wait.

B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter  What do each of the following mean? Write an example of how each could be used. Symbol = < <= >

Similar presentations


Presentation on theme: "B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter  What do each of the following mean? Write an example of how each could be used. Symbol = < <= >"— Presentation transcript:

1 B065: PROGRAMMING OPERATORS AND SELECTION 2

2 Starter  What do each of the following mean? Write an example of how each could be used. Symbol = < <= > >= <> AND OR NOT

3 Objectives Understand what is meant by selection in programming. Explore selection programming commands: IF, SELECT CASE Understand the use of logical operators.

4 Logical Operator: AND Sometimes, we may have more than one condition involved in a decision. If (age > 65) And (theDay = "Thursday") Then cost = 0.9 * cost End If Other Examples: (7 4) is True (6 <> 5) And (6 < 3) is False

5 Logical Operator: OR Sometimes we are happy to accept either of two conditions as the basis for carrying out some action. We might want to issue an error message if a mark is entered as either less than 0 or greater than 100, for example. The logical Or operator is provided to deal with this situation. If (mark 100)Then Console.WriteLine("Error in data") End If

6 Combining Logical Operators It is possible to form quite complicated expressions by combining conditions with several logical operators. For example, ((status = "Temp") And (hours < 30)) Or (status = "Part-time") will be True in two cases status has the value "Temp" and hours has a value less than 30 status has the value "Part-time“ In such compound conditions, the bracketing is vitally important.

7 Simplifying Selection with CASE Nested IF statements can become somewhat confusing and hard to write and later interpret. Sometimes a CASE statement can be used, which is a list of options to compare something to. If there is a match, then some statements can then be executed.

8 A Worked Example of CASE

9 Tasks Complete questions 7 - 12 in Chapter 4 of your handbook. Complete all for homework.

10 Objectives Review Understand what is meant by selection in programming. Explore selection programming commands: IF, SELECT CASE Understand the use of logical operators.

11 Required Reading Each week you will be given required reading. If you fail to do this, you will 100% find the lessons which follow it EXTREMELY difficult. Before next lesson you should have read: Pre-reading – Chapter 5

12 Plenary We will now go through each of the solutions for the tasks set. Each person will show their code as an example and explain what it does.


Download ppt "B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter  What do each of the following mean? Write an example of how each could be used. Symbol = < <= >"

Similar presentations


Ads by Google