Jump to content

Conditional structures: Difference between revisions

Add PL/I
(Go explanation)
(Add PL/I)
Line 2,000:
(T # Else execute final expression(s)
(do-something-else) ) )</lang>
 
=={{header|PL/I}}==
===if-then-else===
 
<lang pli>if condition then
statement;
else
statement;
 
if condition then
do;
statement-1;
.
.
statement-n;
end;
else
statement;</lang>
 
=== case ===
The PL/I 'case' statement has two possible formats:
 
==== select - format 1 ====
<lang pli>select (i); /* select on value of variable */
when (1,4,9)
do;
statement(s)
end;
when (11, 42)
do;
statement(s)
end;
other /* everything else */
do;
statement(s)
end;
end;</lang>
 
==== select - format 2 ====
<lang pli>select; /* select first matching condition */
when (i = 4);
do;
statement(s)
end;
 
when (this = that)
do;
statement(s)
end;
 
when (string = 'ABCDE')
do;
statement(s)
end;
 
other
do;
statement(s)
end;
end;</lang>
 
Notes:
 
* in PL/I there is no fall-through to the next '''when'''. When execution reaches the end of a matching clause, it continues after the end of the select statement, not in the code for the next case.
* the '''do''' ... '''end''' statements can be omitted if the when clause is followed by a single statement.
* if no '''other''' (or in full: '''otherwise''') statement is present and non of the '''when''' cases is matched, the program will end in error.
 
=={{header|Pop11}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.