Conditional structures: Difference between revisions

→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)"
(Add example for Grain)
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
Line 8,323:
<syntaxhighlight lang="vbnet">Dim result As String = If("pants" = "glasses", "passed", "failed") ' type is inferred</syntaxhighlight>
 
=={{header|V (Vlang)}}==
If and match are the general purpose conditional structures in V (Vlang), although the language certainly contains other conditional elements.
===If===
Simplest usage is,
<syntaxhighlight lang="v (vlang)">if boolean_expression {
statements
}</syntaxhighlight>
The braces are required, even around a single statement.
<syntaxhighlight lang="v (vlang)">if boolean_expression {
statements
} else {
Line 8,338:
}</syntaxhighlight>
Braces are required around else clauses, as above, unless the statement of the else clause is another if statement. In this case the statements are chained like this,
<syntaxhighlight lang="v (vlang)">if boolean_expression1 {
statements
} else if boolean_expression2 {
Line 8,347:
===Match===
Simple usage is,
<syntaxhighlight lang="v (vlang)">match true {
boolean_expression1 {
statements
Line 8,364:
 
Match can also switch on the value of an expression, as in,
<syntaxhighlight lang="v (vlang)">switch expression_of_any_type {
value1 {
statements
451

edits