B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter What do each of the following mean? Write an...
-
Upload
dwight-phelps -
Category
Documents
-
view
220 -
download
0
Transcript of B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter What do each of the following mean? Write an...
B065: PROGRAMMINGOPERATORS AND SELECTION 2
Starter What do each of the following mean? Write an example of
how each could be used.Symbol=<<=>>= <>ANDORNOT
Objectives• Understand what is meant by selection in programming.
• Explore selection programming commands: IF, SELECT CASE
• Understand the use of logical operators.
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 * costEnd If
• Other Examples:
(7 < 10) And (7 > 4) is True(6 <> 5) And (6 < 3) is False
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
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.
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.
A Worked Example of CASE
Tasks• Complete questions 7 - 12 in Chapter 4 of your handbook.• Complete all for homework.
Objectives Review• Understand what is meant by selection in programming.
• Explore selection programming commands: IF, SELECT CASE
• Understand the use of logical operators.
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
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.