Conditional structures: Difference between revisions
Content added Content deleted
PatGarrett (talk | contribs) (→If Else End If: add a syntax) |
PatGarrett (talk | contribs) (→{{header|Visual Basic}}: Section added) |
||
Line 5,855: | Line 5,855: | ||
n = 1 @CASE results: n == 1(2c) |
n = 1 @CASE results: n == 1(2c) |
||
n = 2 @CASE results: else</lang> |
n = 2 @CASE results: else</lang> |
||
=={{header|Visual Basic}}== |
|||
===if-then-else=== |
|||
====Block form==== |
|||
<lang vb> |
|||
If condition1 Then |
|||
statement |
|||
End If |
|||
If condition1 Then |
|||
statement |
|||
ElseIf condition2 Then |
|||
statement |
|||
... |
|||
ElseIf conditionN Then |
|||
statement |
|||
Else |
|||
statement |
|||
End If |
|||
</lang> |
|||
====Line form==== |
|||
<lang vb> |
|||
If condition Then statement |
|||
If condition Then statement Else statement |
|||
</lang> |
|||
===select-case=== |
|||
<lang vb> |
|||
Select Case Expression |
|||
Case Value1: statement |
|||
Case Value2: statement |
|||
... |
|||
Case ValueN: statement |
|||
Case Else: statement |
|||
End Select |
|||
Select Case Expression |
|||
Case Value1 |
|||
statements |
|||
Case Value2 |
|||
statements |
|||
... |
|||
Case ValueN |
|||
statements |
|||
Case Else |
|||
statements |
|||
End Select |
|||
===inline if-then-else=== |
|||
<lang vb> |
|||
IIf(expr, then-value-, elsevalue-2) |
|||
</lang> |
|||
Example: |
|||
<lang vb> |
|||
myName = 2 |
|||
Debug.Print IIf(myName = 1, "John", "Jack") |
|||
'return : "Jack") |
|||
</lang> |
|||
===inline switch=== |
|||
<lang vb> |
|||
Switch(expr-1, value-1[, expr-2, value-2 … [, expr-n,value-n]]) |
|||
</lang> |
|||
Example: |
|||
<lang vb> |
|||
myName = 2 |
|||
Debug.Print Switch(myName = 1, "James", myName = 2, "Jacob", myName = 3, "Jeremy") |
|||
'return : "Jacob" |
|||
</lang> |
|||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |