Upcoming SlideShare
×

# Decisions

325 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
325
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
2
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Decisions

1. 1. Making Decisions VB.NET 1
2. 2. 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
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. 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
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 valid statement,including other IF statements.A compound condition is two or moreconditions joined by a logical operator. 14