Discuss Scratch

Guenhael
New Scratcher
5 posts

Repeat until var < 5 does not work !

I've got a basic script that perfoms following code:


Set var to 0
show “var”
Repeat until var <5
increment var
say “hello”
wait 1 second
say “”
wat 1 second
end repeat

say “goodbye”


(i've got the.sb2 file of course, but do not see how to upload it in this form …).

The script goes into the loop and says “Hello” for 1 second, then clears the “say” box during 1 second …. but it never gets out of the loop !

I see the “var” variables values : looks perfect, starts at “0”, then “1”, …“5” (should get out the loop, but does not …), then “6”, “7” …

So, what's wrong with this “var < 5” test on the “repeat until” condition ?
Using “var=5” instead does nor solve the problem …

Thanks,

Guenhaël

deck26
Scratcher
1000+ posts

Repeat until var < 5 does not work !

Check that what you have looks like this including block colours

set [var v] to [0]
show variable [var v]
repeat until <(var) < [5]>

end
I've omitted the rest of the code as it's not relevant. That repeat loop will end immediately since var is less than 5 the first time you check.
Guenhael
New Scratcher
5 posts

Repeat until var < 5 does not work !

Hi,

Thanks for the answer.
Thats exactly what I have, but it does not behave the way it should

The condition, as described in Scratch doc, is evaluated that way :

As long as the test is evaluated to “false”,the script restart inside blocks execution, the test again ..
So, the inside instructions are executed as long as the test is false.

So you're right : I should never get inside the “repeat” instructions since the test is “true” at the very beginning (0<5 is true) … but nonetheless, I execute the inside instruction … and my “var” variable increments from “1” to …. infinite inside the loop. If we had a bad comprehension of the repeat abort condition, I should at least observe something when “va”r reaches 5 don't you think ?

I really do not understand ..

By the way, if I change and make “var > 5”, starting with var=0, I do not go inside the loop at all this time: I go straight to “goodbye” … and I should not since 0>5 is false. But If I start with var=6 … the behaviour is the same : straight to “goodbye” !!!!



So, to summarize, in both case (> and <), the initial value does not modify the repeat loop behavior : I always get inside infinite loop with “<” consition, and never get inside loop with “>” condition: crazy no ?


Guenhaël
Cameron_Johnson
Scratcher
100+ posts

Repeat until var < 5 does not work !

when green flag clicked
set [var v] to [number of times you want to say hello]
repeat (var)
say [hello]
wait (1) secs
say [ ]
wait (1) secs
end
say [goodbye]

Click this link for an example and click “See Inside”

Last edited by Cameron_Johnson (Nov. 22, 2016 14:34:32)

deck26
Scratcher
1000+ posts

Repeat until var < 5 does not work !

Check that you don't have a space before or after the ‘5’ as i suspect that's the most likely problem.
Guenhael
New Scratcher
5 posts

Repeat until var < 5 does not work !

Hi,

No, no space before or after ….I really suspect a bug in Scratch there …
Did you test it on your own and notice the problem ?
Is therea way to post my .sb2 file on theforum ? I have not seen any button to do that, that's too bad !
deck26
Scratcher
1000+ posts

Repeat until var < 5 does not work !

You can upload your project. I think you create new project and then use the upload option from the file menu. I don't use Scratch offline so can't check.

It's unlikely to be a bug but we need to see what you have.
Guenhael
New Scratcher
5 posts

Repeat until var < 5 does not work !

I shared it : called “repeatUntil” …
deck26
Scratcher
1000+ posts

Repeat until var < 5 does not work !

You need to drag and drop the variable from the list of variables and put it in the ‘if’ block. That's why I said the block colours should match my script in the first post - the variable should be an orange block.

What you're doing is comparing the text string ‘var’ with the text string ‘5’ and changing the variable called var will not affect that - you're still comparing the same text strings every time!
Guenhael
New Scratcher
5 posts

Repeat until var < 5 does not work !

HI

Ok, thanks, that's the answer.
I thought it was possible to give the name of the variable in free text, as for other languages, did not see I had to explicitely drag and drop the variable from the left “data” container.
Now it works, thanks again,

Guenhaël.
deck26
Scratcher
1000+ posts

Repeat until var < 5 does not work !

Guenhael wrote:

HI

Ok, thanks, that's the answer.
I thought it was possible to give the name of the variable in free text, as for other languages, did not see I had to explicitely drag and drop the variable from the left “data” container.
Now it works, thanks again,

Guenhaël.

An easy mistake when you're used to other languages.
Scratch_Mapping
Scratcher
100+ posts

Repeat until var < 5 does not work !

I'll put this in Scratchblocks for you
Set [var] to [0]
show variable [var]
Repeat until <(var) < [5] >
change [ var] by (1)
say [hello]
wait (1) secs
say []
wait (1) secs
end
say [goodbye]
deck26
Scratcher
1000+ posts

Repeat until var < 5 does not work !

Scratch_Mapping wrote:

I'll put this in Scratchblocks for you
Set [var] to [0]
show variable [var]
Repeat until <(var) < [5] >
change [ var] by (1)
say [hello]
wait (1) secs
say []
wait (1) secs
end
say [goodbye]
Except your code just repeats the same error in another place!

This topic has been dealt with.

Powered by DjangoBB