Programming - First steps
P.
38 of 349
Wrap
Everything is legible
Wrapping with \\
Even nicer?
Back to the user program: We can further simplify, if we equip the first if function with an else branch
instead of the second if-function. It is worth noting that a statement can not be interrupted by a line
break. If the query condition is not met, the else-branch is executed. Thus, the syntax is:
if
(
Query condition
)
then
Statement{block}1
else
Statement{block}2
endif
So, the implementation of the user program is
[EibPC]
if ("Switch-1/0/0"==ON) then write("Lamp-1/1/1",ON); write("Dimmer-1/1/2"u08,80%) else write("Lamp-1/1/1",OFF); write("Dimmer-1/1/2"u08,0%) endif
You may wonder why this is written so small. The answer is:
We want to suggest: A statement can not be simply interrupted by a newline ("RETURN").
Otherwise, during the compilation by the Enertex
®
EibStudio there would be view a mistake. The
Enertex
®
EibStudio always processes statements line by line. Therefore, once again urgently:
A statement must not be interrupted by a line break.
To make clear more instructions by several lines, use two backslash (\\) characters as wrapping.
Thus we can write our program a little clearer. Furthermore we simplify by the help of the else
branch:
[EibPC]
if ("Switch-1/0/0"==ON) then
\\
write("Lamp-1/1/1",ON);
\\
write("Dimmer-1/1/2"u08,80%) \\
else
\\
write("Lamp-1/1/1",OFF);
\\
write("Dimmer-1/1/2"u08,0%) \\
endif
We recommend to format the user program as just shown. This tremendously increases the
readability for you and thus avoids errors.
Again as a reminder: If several statements are interpreted as a block, a semicolon has to be inserted
between statements.
At if-statements, you can alternatively work with curly brackets({}):
[EibPC]
if ("Switch-1/0/0"==ON) then {
write("Lamp-1/1/1",ON);
write("Dimmer-1/1/2"u08,80%)
} else {
write("Lamp-1/1/1",OFF);
write("Dimmer-1/1/2"u08,0%)
} endif
Now, we can start our program as shown in Figure 4.
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]