60 likes | 290 Views
4b – Nested If/Else. CSCI N331 VB .NET Programming. Lingma Acheson. Department of Computer and Information Science, IUPUI. Nested If/Else Statements. If/Else inside an Else statement: If condition1 Then statement1 Else If condition2 Then statement2 Else
E N D
4b – Nested If/Else CSCI N331 VB .NET Programming Lingma Acheson Department of Computer and Information Science, IUPUI
Nested If/Else Statements • If/Else inside an Else statement: • Ifcondition1Then statement1 Else If condition2 Then statement2 Else If condition3 Then statement3 Else statement4 End If End If End If
Nested If/Else Statements • A grade report example: IfintScore>= 90Then strLetterGrade = “A” Else If intScore >= 80 Then strLetterGrade = “B” Else If intScore >= 70Then strLetterGrade = “C” Else If intScore>= 60 Then strLetterGrade= “D” Else strLetterGrade= “F” End If End If End If End If
Alternative Nested If/Else • “If … Then … ElseIf …” structure • Ifcondition1Then statement1 ElseIfcondition2 Then statement2 ElseIfcondition3 Then statement3 Else statement4 End If • Merge “Else” and “If” into one word. Only need to end the veryfirst “If”.
Alternative Nested If/Else • The grade report example again: IfintScore>= 90Then strLetterGrade = “A” ElseIfintScore >= 80 Then strLetterGrade = “B” ElseIfintScore >= 70Then strLetterGrade = “C” ElseIfintScore>= 60 Then strLetterGrade= “D” Else strLetterGrade= “F” End If