You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by kanishka-karan April 19, 2024
Hi
We are using decrement for loop :
{external}
FUNCTION printf : DINT
VAR_INPUT {ref}
format : STRING;
END_VAR
VAR_INPUT
args: ...;
END_VAR
END_FUNCTION
program inProgram
var
i : DINT;
end : DINT;
end_var
end := -1;
printf('end: %d$N', end);
for i := end to 0 by -1 do
printf('for end: %d$N', end);
end_for;
end_program
The output of the program is :
end: -1
for end: -1
It shows that the for loop code is executing once even if end is equal to -1. We think it should not run the code inside for loop, as the condition is not met.
We interpreted the Structured text for loop
for i := end to 0 by -1 do
as in C/C++ as
for (i= end ; i >= 0; i-- )
Please let us know if we our understanding is correct.
Thank You
The text was updated successfully, but these errors were encountered:
This PR fixes for loops executing once when the predicate already should not be met for decrementing loops.
I have also re-implemented the codegen logic for for-loops, resulting in fewer predecessors and hopefully more
readable IR.
Resolves#1207
This PR fixes for loops executing once when the predicate already should not be met for decrementing loops.
I have also re-implemented the codegen logic for for-loops, resulting in fewer predecessors and hopefully more
readable IR.
Resolves#1207
This PR fixes for loops executing once when the predicate already should not be met for decrementing loops.
I have also re-implemented the codegen logic for for-loops, resulting in fewer predecessors and hopefully more
readable IR.
Resolves#1207
This PR fixes for loops executing once when the predicate already should not be met for decrementing loops.
I have also re-implemented the codegen logic for for-loops, resulting in fewer predecessors and hopefully more
readable IR.
Resolves#1207
Discussed in #1206
Originally posted by kanishka-karan April 19, 2024
Hi
We are using decrement for loop :
The output of the program is :
It shows that the for loop code is executing once even if
end
is equal to -1. We think it should not run the code insidefor
loop, as the condition is not met.We interpreted the Structured text for loop
as in C/C++ as
Please let us know if we our understanding is correct.
Thank You
The text was updated successfully, but these errors were encountered: