Page 1 of 1

Loop index

Posted: Mon Mar 19, 2018 11:33 pm
by mnf
Hi,

I've seen similar to this reported back in 2014.
A loop with a count > 255 needs a word as the index and this indeed now works when using an integer count.
However if using a variable as the loop index then flowcode only assigns a byte variable.

[img]
loop.png
(8.02 KiB) Downloaded 1070 times
[/img]

Generates (correctly)

Code: Select all

MX_UINT16 FCLV_LOOP1;
.
.
    for (FCLV_LOOP1=0; (FCLV_LOOP1)<(1000); (FCLV_LOOP1)++)
Whereas
[img]
loop2.PNG
(6.47 KiB) Downloaded 1070 times
[/img]

Where x is greater than 8 bits generates the following C

Code: Select all

MX_UINT8 FCLV_LOOP1;

.
.
    for (FCLV_LOOP1=0; (FCLV_LOOP1)<(FCV_X); (FCLV_LOOP1)++)
Which of course fails if x > 255 - FCLV_LOOP1 should mirror the type of 'x'

A workaround is easy - using a user-defined loop variable in a 'for' loop or a 'repeat until' loop.

It can catch the unwary however.....

Martin

Re: Loop index

Posted: Tue Mar 20, 2018 12:30 pm
by Benj
Thanks Martin,

Yes this has caught me out too, I'll flag it up as a bug in the system.