Manual – IPOSplus®
197
16
if...else
Compiler – Constructions
16
Compiler – Constructions
The IPOS
plus®
Compiler provides constructions that are also available in other high-
level languages.
The following constructions are available:
• if...else
• for
• while
• do...while
• switch...case...default
These are supplemented by statements such as 'continue' and 'break', which are used
as control elements within these constructions.
16.1 if...else
16.1.1 Syntax
The key words if and else control the program flow depending on whether the expres-
sion following the key word if returns the value TRUE (not equal to zero) or FALSE
(equal to zero). The else branch is optional. It is performed if the expression returns the
value FALSE. In a special case, a statement can also be a block in which several state-
ments can be specified. In this case, the statement block must be enclosed by curly
brackets ( {statement block} ).
The expression may also be composed of several conditions which are logically inter-
linked. Consequently, logical AND ( && ) and logical OR ( ¦¦ ) are available as logic op-
erations.
Example
Variable H2 is set to the value 10 if H1 is greater than or equal to 3 and is also less than
or equal to 12. In other words: H2 is set to the value 10 if the value of H1 is between 3
and 12.
The internal brackets are not necessary, but they increase the legibility of the program.
if ( expression )// Instructionelse// Instruction
Without else branch
With else branch
With block as if branch
With block as else branch
if ( H1 == 3 )
H2 = 10;
if ( H1 == 3 )
H2 = 10;
else
H2 = 8;
if ( H1 > 3 )
{
H2 = 10;
H3 = 11;
}
if ( H1 > 3 )
H2 = 9;
else
{
H2 = 10;
H3 = 11;
}
INFORMATION
Potential problem: A ; (semicolon) at the end of an if statement always makes the con-
dition true.
if ( ( H1 >= 3 ) && ( H1 <= 12 ) )
H2 = 10;
P
i
f
kVA
Hz
n
P
i
f
kVA
Hz
n