This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-03-07 08:28:34

liupengty
Scratcher
Registered: 2009-08-24
Posts: 41

Help ,Help

My project is here :
parachuting跳伞

I 'd like to repeat  10 times

but I don't understand why only run it once 

Who can help me ?

Thanks!

Last edited by liupengty (2012-03-07 08:31:18)

Offline

 

#2 2012-03-07 08:41:33

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Help ,Help

Repeat what ten times?


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#3 2012-03-07 08:55:03

liupengty
Scratcher
Registered: 2009-08-24
Posts: 41

Re: Help ,Help

when green flag clicked
repeat (10)
 set  [tiaosanX]  to  (250)
 forever if <(tiaosanX) > [-300]>
     change [tiaosanX] by <pick random(-3)to(-1) >
 end
end
I 'd like to repeat  10 times

but I don't understand why only run it once

Last edited by liupengty (2012-03-07 09:21:33)

Offline

 

#4 2012-03-07 09:23:12

liupengty
Scratcher
Registered: 2009-08-24
Posts: 41

Re: Help ,Help

Hello everyone please help me

henley ?

Last edited by liupengty (2012-03-07 09:23:46)

Offline

 

#5 2012-03-07 09:50:08

liupengty
Scratcher
Registered: 2009-08-24
Posts: 41

Re: Help ,Help

and ,this can repeat  10 times,as follows:

when green flag clicked
repeat (10)
 set  [tiaosanX]  to  (250)
 repeat until <(tiaosanX) < [-300]>
     change [tiaosanX] by <pick random(-3)to(-1) >
end
end

Offline

 

#6 2012-03-07 10:05:28

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Help ,Help

Ok, here's the thing. The forever if block is synonymous to:

forever
if <blah>
blah
end
So as soon as you enter a forever loop, even if it's forever if, you know you will never come out. Like a life sentence. So in your code, the forever block doesn't stop when tiaosanX is less than -300; it keeps waiting for it to get above -300 so it can evaluate again.

Now your solution: it's perfect. "Repeat until" is exactly what you need. Repeat until repeats the given code, until (ha!) the condition given is true. So then tiaosanX is below -300, it stops evaluationg, the program moves on, back to the beginning of the repeat block.

Hope this helped. If not, think of it this way: any block whose bottom if flat (eg forever, forever if, stop all, etc. They're called cap blocks) will never, ever continue evaluation of the script; the evaluation stops at them no matter what. So if you put forever if there, the evaluation of the first repartition will never complete, so you won't see it repeat.  wink


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7 2012-03-07 20:09:11

liupengty
Scratcher
Registered: 2009-08-24
Posts: 41

Re: Help ,Help

Thank you very much for all your help and useful information
and ,I see.......... big_smile
Thanks again!!!

Offline

 

Board footer