For (ESDL Editor)
The for loop stands out as one of the modeling features that are available in ESDL only. There is no equivalent in block diagrams.
The for loop has the following general form:
for ( initExpression; expressionLog; incrExpression )
{
This is equivalent to
initExpression;
while (expressionLog) {
loopStatement;
incrExpression; }
In the for loop, every component of the loop head, initExpression, expressionLog, and incrExpression, is optional. The loop condition expressionLog must be of type logical. It is set to true if omitted, which results in an infinite loop.
In ESDL, the components of the loop head are checked for compliance with MISRA-C:2012 rule 14.3:
The first part, initExpression, shall obey the following rules:
initExpression is empty, OR initExpression assigns a value to the loop counter.
The loop counter is an element of integer type with an ident formula.
If the rules are violated, warnings are issued during code generation.
violated rule
warning message
a)
WMdl888
b)
WMdl8885
The second part, expressionLog, shall obey the following rules:
- expressionLog has no side effects.
- expressionLog uses the loop counter and – optionally – loop control flags.
- expressionLog uses no other object that is changed in the loop body.
If the rules are violated, warnings are issued during code generation.
violated rule
warning message
a)
WMdl8881
b)
WMdl8882
c)
WMdl8883
The third part, incrExpression, shall obey the following rules:
- incrExpression modifies only the loop counter, without any side effects.
- incrExpression does not use any object that is changed in the loop body.
If the rules are violated, warnings are issued during code generation.
violated rule
warning message
a)
WMdl8884
b)
WMdl8883
In order to avoid infinite loops, the maximal number of loop iterations can be limited to a fixed number in the project properties, Experiment Code node, of the associated project (or default project).
See also