12
B065: PROGRAMMING OPERATORS AND SELECTION 2

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

Embed Size (px)

Citation preview

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

B065: PROGRAMMINGOPERATORS AND SELECTION 2

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

Starter What do each of the following mean? Write an example of

how each could be used.Symbol=<<=>>= <>ANDORNOT

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

Objectives• Understand what is meant by selection in programming.

• Explore selection programming commands: IF, SELECT CASE

• Understand the use of logical operators.

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

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

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

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

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

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.

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

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.

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

A Worked Example of CASE

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

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

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

Objectives Review• Understand what is meant by selection in programming.

• Explore selection programming commands: IF, SELECT CASE

• Understand the use of logical operators.

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

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

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

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.