Count in Thunkable produces extra iterations
You will see that the count, loops three even when the “to value”(length of the) is 0. You can try with 0 values in the “from” of the count and then it loops twice. Only at the higher values it works logically. In the C world:
If (i = 0; i = 0; i++) {

would not loop even once.

So obviously you’ve provided blocks that are a mistake:

And you’re right, they shouldn’t do anything. But instead they act unpredictably. I suppose there should be better error checking with the [count with] block.

But also… why not just avoid a situation like that? Do you think it’s likely you’d use a variable as a range value that might exceed the valid range for an iterative loop? I haven’t run into that situation but it’s certainly conceivable.

1 Like

when you use a count_with block where the start_val is greater than end_val, it means you’re counting down , so your step_value should really be (-1) as shown below


and this is the result as expected

it looks like thunkable assumes you’re counting down when it sees this condition, so it automatically adjusts the iterator to have the correct sign. even if you entered 1, it internally becomes -1.

if you think about it, if you use +1 as your step_value, and you start with 5, you will never get to 4!

(i don’t know if this is a bug or a feature)


also results

this is why your block set up counts twice.

1 Like

Yes, that’s the conclusion I reached, too.

1 Like

Hi Tatiang, As you said it is conceivable. I saw this bug when was doing this block:

So normally AddRowCount is a large figure and things were working fine. There was some other bug and AddRowCount went to zero and then I got two rows of data!! I was surprised. That is how ran into this issue. In C it would never proceed so the bug would never surface.

Manyone thanks a lot, you analyzed it rightly. It never occurred to me that it was going negative and hence doing the two. Once you explained it is very clear. So technically if one thinks in C wise it is bug but Thunkable doing the right thing as explained.

even if you entered 1, it internally becomes -1.
Thanks to both. I have to be more diligent and avoid such situation.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.