Old HDevelop programs (prior to HALCON 11) have different semantics of
for loops compared to other programming languages.
If an old HDevelop program is opened, the for loops are labeled to be
run in a compatibility mode to simulate the old behavior.
To avoid confusions about the exported code, it is recommended to disable the
compatibility mode by removing the special __use_internal_index__ tag.
See the reference manual of the for operator for more information.
The following applies only to old HDevelop programs using the compatibility
mode that are going to be exported.
Because the problems are so rare and the generated
code would become very difficult to understand otherwise, the code generation
ignores the different semantics. These differences are:
- In the programming languages, you can modify the loop variable (e.g., by
setting it to the end value of the condition) to terminate the loop. This
can't be done in HDevelop because here the current value is stored
“inside” the for-operator and is automatically updated when it is
executed again.
- In the programming languages, you can modify the step range if you use a
variable for the increment. This is also not possible with HDevelop because
the increment is stored “inside” the for-operator when the loop is
entered.
- The last difference concerns the value of the loop variable after exiting the
loop. In the programming languages, it has the value with which the condition
becomes false for the first time. In HDevelop it contains the end value,
which was calculated when the loop was entered.
Looking at the mentioned points, we recommend that you program
according to the following rules:
- Don't modify the loop variable or the step value inside the
loop. If you need this behavior, use the while-loop.
- Don't use the loop variable after the loop.