Download presentation
Presentation is loading. Please wait.
1
OPERATORS AND SELECTION 2
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 < 10) And (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 < 0) Or (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 6-12 in Chapter 4 of your handbook.
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
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.