• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Decisions
 

Decisions

on

  • 423 views

 

Statistics

Views

Total Views
423
Views on SlideShare
247
Embed Views
176

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 176

http://moodle.wortech.ac.uk 176

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Decisions Decisions Presentation Transcript

    • Selection Statements VB.NET 1
    • 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
    • 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
    • The IF Statement Conditions 4
    • Simple IF Statements (design)Decision symbol Process symbol 5
    • Solving the Overtime Problem 6
    • 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
    • True OR False Conditions 9
    • 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
    • Logical Operators 11
    • 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 validstatement, including other IF statements.A compound condition is two or moreconditions joined by a logical operator. 14