1 / 5

4b – Nested If/Else

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

nessa
Télécharger la présentation

4b – Nested If/Else

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4b – Nested If/Else CSCI N331 VB .NET Programming Lingma Acheson Department of Computer and Information Science, IUPUI

  2. 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

  3. 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

  4. 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”.

  5. 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

More Related