'repeat until' block - incorrect code generated


#1

Does anybody have any idea why the generated logical test for the repeat until block contain a negation?
Simple example:
Repeat until 25 < 50

This loop should run forever as 25 is always less than 50

The python code generated is:
while not 25 < 50:
sprite.play(‘meow’)

Why is there a ‘not’ in the test?

Same for generating code for Arduino:
while(!(25 < 50))
{
_loop();
Serial.println(“hello”);

}

Any idea how to fix this? Is this a bug?
Tried it on both Windows/Mac/Web editor and the logical test always contains the negation.


#2

A repeat until (AKA do until) equivalent is while not.

Lets say it in full text"Repeat the loop until this is true (i.e stop doing the loop once it is true)" or we can say "keep doing this loop while this isn’t true (i.e stop doing the loop once it is true)


#3

Thanks for the reply!

I did test this in Scratch and it behaves the same way. Oh well, maybe my logic is off.


#4

Agree with OutoftheBOTS

Repeat until 25 > 50 would repeat forever, because the condition is never true. What you’re perhaps thinkings of is “repeat while” logic.


#5

I am indeed thinking of the ‘repeat while’ logic.


#6

In Pascal/Delphi there is a clear logic difference in ‘while’ and ‘until’ loops that may confuse Scratch users who used to use those loops. I also struggled with that.
‘While’ has condition check in the start of the loop - ‘while (condition) do (code loop)’
‘Until’ has condition check in the end of the loop - ‘repeat (code loop) until (condition)’

In Scratch/mBlock the loop behavior is ‘until (condition) do (code loop)’ - condition check is before the loop starts. This also can be noticed on the image of the loop block.

The real problem is that in mBlock in some languages like Russian ‘repeat until’ is translated as ‘repeat while’ (“повторять пока”). However in original Scratch it is translated correct as ‘repeat while not’ (“повторять пока не”). Developers please fix it!