Conditional structures: Difference between revisions

Content added Content deleted
m (Fix the Dao example.)
(→‎{{header|AWK}}: with braces)
Line 329: Line 329:
Conditionals in awk are modelled after C:
Conditionals in awk are modelled after C:
<lang awk>if(i<0) i=0; else i=42</lang>
<lang awk>if(i<0) i=0; else i=42</lang>
For a branch with more than a single statement, this needs braces:
including the ternary conditional
<lang awk>
if(i<0) {
i=0; j=1
} else {
i=42; j=2
}</lang>
There is also the ternary conditional:
<lang awk>i=(i<0? 0: 42)</lang>
<lang awk>i=(i<0? 0: 42)</lang>