Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

  • Be the first to comment

  • Be the first to like this


  1. 1. Selection Statements VB.NET 1
  2. 2. ObjectivesUnderstand how relational operators areused to create a conditionUnderstand and use IFstatements, including nested IF statementsUnderstand and use compound conditionsDevelop and evaluate multiple solutions tothe same problemSuccessfully write program solutions thatrequire decision making 2
  3. 3. 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
  4. 4. The IF Statement Conditions 4
  5. 5. Simple IF Statements (design)Decision symbol Process symbol 5
  6. 6. Solving the Overtime Problem 6
  7. 7. 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
  8. 8. Nested IF Statements (design)The term nested IF refers toan IF statement containedwithin the true or falsebranch of another IFstatement. 8
  9. 9. True OR False Conditions 9
  10. 10. 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
  11. 11. Logical Operators 11
  12. 12. 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
  13. 13. The Select…..Case StatementWhen more choices are available use theSelect – Case statement, an example isshown below. 13
  14. 14. 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 validstatement, including other IF statements.A compound condition is two or moreconditions joined by a logical operator. 14