Presentation is loading. Please wait.

Presentation is loading. Please wait.

EGR 141 Computer Problem Solving in Engineering and Computer Science

Similar presentations


Presentation on theme: "EGR 141 Computer Problem Solving in Engineering and Computer Science"— Presentation transcript:

1 EGR 141 Computer Problem Solving in Engineering and Computer Science
IF and CASE

2 Decisions If condition Then ‘ statement(s) End If
True False Steps to process if condition is true If condition Then ‘ statement(s) End If If condition Then ‘ statement(s) for true Else ‘ statement(s) for false End If Condition ? True False Steps to process if condition is true false

3 Decisions

4 Decisions

5 Decisions Check the invalid cases in the condition
Make sure that salary is between $500 and $2500: If Not (Salary >= 500 And Salary <= 2500) Then ‘ do error processing since outside range limits End If is equivalent to If Salary < 500 Or Salary > 2500 Then

6 Decisions Check the invalid cases in the condition
Make sure that age is between 21 and 75: If CInt(txtAge.Text) < 21 OR _ CInt(txtAge.Text) > 75 Then ‘ do error processing since outside range limits End If Make sure single people have no spouse If txtStatus.Text = “single” AND txtSpouse.Text <> “” Then ‘ do error processing - spouse given for single person

7 Decisions If condition1 Then Statements for steps ABC
statement(s) for condition1 and condition2 true Else statement(s) for condition1 true and condition2 false End If Statements for steps XYZ statement(s) for condition1 false Condition1 ? False True Steps to process if condition 1 is false Condition2 ? Steps to process if condition1 is true and condition2 is false Steps to process if both condition1 and condition2 are true Steps ABC Steps XYZ Note the indentation

8 Decisions IF… THEN ELSEIF… THEN If condition1 Then If condition1 Then
Statements for steps ABC End If If condition2 Then Statements for steps DEF If condition3 Then Statements for steps GHI If condition4 Then Statements for steps JKL Statements for steps XYZ Else statement(s) for condition1 false If condition1 Then Statements for steps ABC ElseIf condition2 Then Statements for steps DEF ElseIf condition3 Then Statements for steps GHI ElseIf condition4 Then Statements for steps JKL Statements for steps XYZ Else statement(s) for condition1 false End If IF… THEN ELSEIF… THEN

9 Decisions Note the indentation Select Case expression Case cond1
True False Steps to process if cond1 True Case expression cond2 Steps to process if cond2 True condn Steps to process if condn True Steps to process if condn False When every decision in nested if compares values against the same expression Select Case expression Case cond1 statement(s) for cond1 true Case cond2 statement(s) for cond1 false and cond2 true : Case condn statement(s) for cond1-condn-1 false and condn true Case Else statement(s) for al conditions false End Select Note the indentation


Download ppt "EGR 141 Computer Problem Solving in Engineering and Computer Science"

Similar presentations


Ads by Google