Control Structures

In CONTROL all common control structures according to the syntax of ANSI-C are available. You can find a detailed description in the online help Control structures in CTRL.

if ( <evaluation_expression_A> )

{

<statement(s)B >

// Program code for part A

}

else if ( <evaluation_expression_B> )

{

<statement(s) B>

// Program code for part B

}

else

<statement C>

// Individual statement for part C: is only executed // when neither evaluation_expression_A nor _B is TRUE. // ...possible as individual statement also without brackets

All evaluation expressions in an if/else construct have to return a boolean value so that a TRUE/FALSE decision is possible.

switch( <evaluation_expression> )

{

case( <result1> ): {

<statement(s)_1>

// ...Program code

break;

}

case( <result2> ): {

<statement(s)_2>

// ... Program code

break;

}

//...

case( <resultn> ): {

<statement(s)_n>

// ... Program code

break;

}

default: {

// ... Program code

break;

}

}

All evaluation expressions in a switch/case construct have to return a value that can be compared in a case() expression with a result.

for (i = 1; i <= 15; i++) // i++ means i = i + 1

{

// Program code that is executed repeated

}

With a for loop you can run a sequence of statements with a given number of repeats. Naturally you can define the start values, end values and increments of loop variables (in the above example "i") also flexibly using variables. The above loop would run through exactly 15 times whereas i would be increased by 1 based on the initial value 1.

while ( <evaluation_expression> )

{

// Permanent executed program code

}

do

{

// Permanent executed program code

} while ( <evaluation_expression> )

The while construct runs the comprised code as long as the control expression that must return a boolean result, is TRUE. If the control expression is not fulfilled, the loop will never be executed.

The do-while construct corresponds basically to the while construct but the code in the core of the construct will be executed at least once since the control expression will be checked only at the end of the first run. The loop can be interrupted straight with the command break.