# 嵌套和非嵌套的else / else ifs之间有区别吗？

[英]Is there a difference between nested and non nested else/else ifs?

``````If (termNumber = TermNumberCode.FallWinter) Then
Dim first_term As String = " ((Course.dbo.CourseList.[Year])=@TermYear) AND ((Course.dbo.CourseList.TermNumber)=3)  "

Dim second_term As String = " ((Course.dbo.CourseList.Year)=@TermYear+1) AND ((Course.dbo.CourseList.TermNumber)=1)  "
query &= "  AND ( ( " & first_term & " ) OR ( " & second_term & " ) )  "

Else
If (termNumber = TermNumberCode.Summer) Then
query &= " AND ((Course.dbo.CourseList.[Year])=@TermYear) AND ((Course.dbo.CourseList.TermNumber)=2)  "

ElseIf (termNumber = TermNumberCode.Fall) Then
query &= " AND ((Course.dbo.CourseList.[Year])=@TermYear) AND ((Course.dbo.CourseList.TermNumber)=3)  "

ElseIf (termNumber = TermNumberCode.Winter) Then
query &= " AND ((Course.dbo.CourseList.[Year])=@TermYear) AND ((Course.dbo.CourseList.TermNumber)=1)  "

End If
End If
``````

``````If (termNumber = TermNumberCode.FallWinter) Then
code...

Else if (termNumber = TermNumberCode.Summer)
code...

Else If (termNumber = TermNumberCode.Fall)
code...

Else //(termNumber = TermNumberCode.Winter)
code...
``````

``````if #1..
else
if #2..
else if #3..
else ..
end
``````

``````if #1..
else if #2..
else if #3..
else ..
``````

VB.NET有if和else两种语法。 第一种风格的第一个声明是紧跟在`Then``Else` ，没有插入的冒号或行尾。 条件的效果将延伸到行尾。 此样式不允许使用`End If`