Conditional structures: Difference between revisions

Content added Content deleted
(fix z80 sections to not clutter table of content)
Line 5,252: Line 5,252:
* [http://www.php.net/manual/en/language.control-structures.php php.net:Control Structures]
* [http://www.php.net/manual/en/language.control-structures.php php.net:Control Structures]
* [http://www.php.net/manual/en/control-structures.switch.php php.net:Control Structures: Switch]
* [http://www.php.net/manual/en/control-structures.switch.php php.net:Control Structures: Switch]

=={{header|Picat}}==
Picat is a multi-paradigm language (based on Prolog) and has some different conditional structures:
* "direct" testing: The program will not continue if not satisfied.
* <code>if/then/elseif/else/end</code>: Traditional if/then/else construct.
* <code>(condition -> then-part ; else-part)</code>: From Prolog.
* <code>Ret = cond(condition,then-part,else-part)</code>: Function which returns the appropriate value.
* As a predicate: From Prolog.
* As condition in a function's head.

Here are examples of each of these constructs.

<lang Picat>go =>
N = 10,

% "direct" test that will fail if not satisfied
N < 14,

% if/then/elseif/else
if N < 14 then
println("less than 14")
elseif N == 14 then
println("is 14")
else
println("not less than 14")
end,

% From Prolog: (condition -> then ; else)
( N < 14 ->
println("less than 14")
;
println("not less than 14")
),

% Ret = cond(condition, then, else)
println(cond(N < 14, "less than 14", "not less than 14")),

% as a predicate
test_pred(N),

% as condition in a function's head
println(test_func(N)),

println(ok), % all tests are ok
nl.

% as a predicate
test_pred(N) ?=>
N < 14,
println("less than 14").
test_pred(N) =>
N >= 14,
println("not less than 14").
% condition in function head
test_func(N) = "less than 14", N < 14 => true.
test_func(_N) = "not less than 14" => true. </lang>

{{out}}
<pre>less than 14
less than 14
less than 14
less than 14
less than 14
ok</pre>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==