Conditional structures: Difference between revisions

Content added Content deleted
(Added formating)
No edit summary
Line 331: Line 331:
including the ternary conditional
including the ternary conditional
<lang awk>i=(i<0? 0: 42)</lang>
<lang awk>i=(i<0? 0: 42)</lang>

=={{header|Babel}}==

===Simple select===

<lang babel>
"foo" "bar" 3 4 > sel <<
</lang>

Prints "foo" since '3 4 >' evaluates to false, which causes sel to remove "bar" from the stack.

===If-Then-Else===

<lang babel>
{3 4 >}
{"foo"}
{"bar"}
ifte
<<
</lang>

Prints "bar" because the first line is the "if", the second line is the "then" and the last line is the "else", and '3 4 >' evaluates to false.

===Conditional===

<lang babel>
({3 4 >} {"Three is greater than four" }
{3 3 >} {"Three is greater than three"}
{3 2 >} {"Three is greater than two" }
{3 1 >} {"Three is greater than one" })
cond
<<
</lang>

Prints "Three is greater than two", as expected.


=={{header|BASIC}}==
=={{header|BASIC}}==