Loop index

A forums to allow bugs and problems with Flowcode v7 to be reported and resolved.

Moderator: Benj

Post Reply
mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Loop index

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Loop index

Post by Benj »

Thanks Martin,

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

Post Reply