Manual – IPOSplus®
203
16
return
Compiler – Constructions
The default branch must – if available – be the last line in a switch statement.
This program extract increments IPOS
plus®
variable H2 if the value of IPOS
plus®
vari-
able H1 is 1. If its value is 2, then the IPOS
plus®
variable H3 is incremented. IPOS
plus®
variable H1 is incremented given any other value of IPOS
plus®
variable H4.
The following variant is also possible:
This program extract increments IPOS
plus®
variable H3 if the value of IPOS
plus®
vari-
able H1 is 1 or 2. IPOS
plus®
variable H1 is incremented given any other value of
IPOS
plus®
variable H4.
16.6 return
The key word
return
ends the processing of a function and returns to the command
following the function call. The
return
statement makes it possible to end functions
prematurely, for example, to increase the clarity of a C program. However, using this
statement too often can have the opposite effect. The following applies: a function
should contain as few exit points as possible.
The following example shows two coding possibilities for achieving the same result. The
example on the left uses the
return
statement to exit the function prematurely,
whereas the example on the right does not use
return
.
switch ( H1 )
{
case 1: ++H2;
break;
case 2: ++H3;
break;
default: ++H4;
break;
}
switch ( H1 )
{
case 1:
case 2: ++H3;
break;
default: ++H4;
break;
}
Function ()
{
// Leave function when H1 is 5
if ( H1 == 5 )
return;
H2=3;
}
Function ()
{
// Skip statement when H1 = 5
if (H1 != 5)
{
H2=3;
}
}
P
i
f
kVA
Hz
n
P
i
f
kVA
Hz
n