ObjectivesUnderstand how relational operators areused to create a conditionUnderstand and use IF statements,including nested IF statementsUnderstand and use compound conditionsDevelop and evaluate multiple solutions tothe same problemSuccessfully write program solutions thatrequire decision making 2
Selection StatementsThe most common decision structure is the IF statement.A condition is a boolean expression that evaluates to eithertrue or false.Comparison operators require numeric operands andproduce a logical result.Conditions typically involve one of six relational operators. Greater than > Less than < Greater than or equal >= Less than or equal <= Equal = Not equal <> 3
VB.net code ExamplePrivate Sub btnCheck_Click() Dim Input, value1, value2 As Integer If Input = value1 Then ‘ Condition 1 is True process A ‘so only this code runs ElseIf Input = value2 Then ‘ Condition 2 is True process B ‘different response Else ‘ Neither condition is True process C ‘can be error message End IfEnd Sub Task 1: Create programs to perform the functions shown in the flow chart examples. Task 2: Create a version(2) of the Correct Change program (from Input/Output) using selection statements. 7
Nested IF Statements (design)The term nested IF refers toan IF statement containedwithin the true or falsebranch of another IFstatement. 8
Compound ConditionsA compound condition consists of twoconditions within parentheses joined by alogical operator.Logical Operators require logical operandsand produce a logical result. NOT Logical opposite AND Both values are true OR At least one value is true XOR Exactly one value is true 10
Operator PrecedenceWhen several operations occur in anexpression, each part is evaluated andresolved in a predetermined order calledoperator precedence. 1st : Evaluate all arithmetic/concatenation operators 2nd : Evaluate all comparison operators 3rd : Evaluate all logical operators 12
The Select…..Case StatementWhen more choices are available use theSelect – Case statement, an example isshown below. 13
SummaryA condition is an expression that evaluatesto either true or false.IF statements use conditions to choosebetween actions.The true and false branches of an IFstatement may contain any valid statement,including other IF statements.A compound condition is two or moreconditions joined by a logical operator. 14
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.