Discuss Scratch

KermitMC
Scratcher
100+ posts

While Loop and For Loop

The For Loop will replace repeat.
The While Loop will replace repeat until

So instead of the block saying “repeat” it will say “For” and instead of the block saying “repeat until” it will say “While”
The blocks will work the same but just have different names.

While some of you may disprove and say this is stupid, Just keep it the same.
In proper code language for loops repeat something a certain amount of times and
while loops repeat when the statement is through and will only stop when it is not.
Sonickyle
Scratcher
1000+ posts

While Loop and For Loop

Keep in mind that Scratch is created with 6+ year olds in mind.
KermitMC
Scratcher
100+ posts

While Loop and For Loop

Sonickyle wrote:

Keep in mind that Scratch is created with 6+ year olds in mind.
I was wondering why the program was made sooo easy to use.
Diamond_Projects
Scratcher
100+ posts

While Loop and For Loop

+1 :: control

Last edited by Diamond_Projects (Sept. 17, 2014 02:26:17)

OmnipotentPotato
Scratcher
1000+ posts

While Loop and For Loop

While is okay, but not sure about the for loop.

One problem, the only languages I'm completely fluent with are Scratch and TI-BASIC (for TI-84 calculators). In TI-BASIC, the for loop is completely different. It's something like this:

For(variable, number#1, number#2, number#3)
Code;
Code;
Code;
Code;
End

Where variable is a variable the loop uses, number#1 is the initial value of variable, number#2 is the ending point of the variable, and number#3 is the rate at which the variable increases every loop. So, the variable starts at number#1 and changes itself by number#3 every time the loop completes until it is greater than or equal to number#2.


This is not at all what you are recommending. Is this what the for loop does in other languages, or just TI-BASIC? Because, if it's like this in other languages, I would say don't do this. Otherwise, support.

tl;dr: no support unless for loop is not what I think it is.

Last edited by OmnipotentPotato (Aug. 25, 2014 02:54:28)

20btheilmanngohr
Scratcher
100+ posts

While Loop and For Loop

I'm fine if the for loop is:
for (10) loops:: c-block control

end
but I don't like while, cause instead of saying “Repeat Until”, it's saying “While”, which sounds more like it runs the script while the boolean is running, most likely to confuse many people, so semi-support.
mathfreak231
Scratcher
1000+ posts

While Loop and For Loop

Replacing “repeat until” with “while” would break many projects as the block would have an opposite meaning, repeating the script until the boolean is false rather than true.

I'd be OK if it were deprecated or something, but really, what's the point? Besides, many programming languages do have an “until” structure, although it works slightly different.
RandomPerson1789
Scratcher
100+ posts

While Loop and For Loop

while loop solution
repeat until <not <condition>>

end
OmnipotentPotato
Scratcher
1000+ posts

While Loop and For Loop

RandomPerson1789 wrote:

while loop solution
repeat until <not <condition>>

end
No, the while block would be the same as repeat until. Exactly the same except for the names.
djdolphin
Scratcher
1000+ posts

While Loop and For Loop

OmnipotentPotato wrote:

RandomPerson1789 wrote:

while loop solution
repeat until <not <condition>>

end
No, the while block would be the same as repeat until. Exactly the same except for the names.
until != while
OmnipotentPotato
Scratcher
1000+ posts

While Loop and For Loop

djdolphin wrote:

OmnipotentPotato wrote:

RandomPerson1789 wrote:

while loop solution
repeat until <not <condition>>

end
No, the while block would be the same as repeat until. Exactly the same except for the names.
until != while

Just saying what the OP said….

The OP wrote:

So instead of the block saying “repeat” it will say “For” and instead of the block saying “repeat until” it will say “While”
The blocks will work the same but just have different names.
stickfiregames
Scratcher
1000+ posts

While Loop and For Loop

For already exists, but it was removed for some reason.
http://scratch.mit.edu/projects/25582648/
It would be nice to have a proper for loop, where you can reference the iteration number.

While is not the same thing as Repeat Until, because While executes if the condition is true at the beginning of the loop, and Repeat Until executes if the condition is false at the end of the loop.

They could add a
repeat while <> :: control cstart
end
but people might confuse it with repeat until.
stickfiregames
Scratcher
1000+ posts

While Loop and For Loop

This is the actual workaround for while:
if <condition :: grey> then
repeat until <not <condition :: grey>>
...
end
end
AonymousGuy
Scratcher
1000+ posts

While Loop and For Loop

stickfiregames wrote:

This is the actual workaround for while:
if <condition :: grey> then
repeat until <not <condition :: grey>>
...
end
end
This is the actual workaround for while:
repeat until <not <condition :: grey>>
...
end
The “if” part isn't needed - if the condition is true, then it will still run the loop. If it's false, the if still isn't necessary, because the repeat until is evaluated as true, and thus cancels.
stickfiregames
Scratcher
1000+ posts

While Loop and For Loop

AonymousGuy wrote:

stickfiregames wrote:

This is the actual workaround for while:
if <condition :: grey> then
repeat until <not <condition :: grey>>
...
end
end
This is the actual workaround for while:
repeat until <not <condition :: grey>>
...
end
The “if” part isn't needed - if the condition is true, then it will still run the loop. If it's false, the if still isn't necessary, because the repeat until is evaluated as true, and thus cancels.

Repeat until is evaluated at the end of the loop. That is why the if <condition> is needed: without it, the loop will run once even if the condition is false.

Last edited by stickfiregames (Aug. 30, 2014 14:28:13)

wag123
Scratcher
21 posts

While Loop and For Loop



when this sprite clicked
if <you want a follow> then

go to [my profile v]
ask [for a follow] and wait
end

Last edited by wag123 (Feb. 15, 2015 03:31:38)

Gaza101
Scratcher
500+ posts

While Loop and For Loop

wag123 wrote:

when this sprite clicked
if <you want a follow> then

go to [my profile v]
ask [for a follow] and wait
end
Please stick to the topic.

Last edited by Gaza101 (Feb. 15, 2015 12:41:56)

TheGamingStar
Scratcher
500+ posts

While Loop and For Loop

Necropost alert!
MrSherlockHolmes
Scratcher
500+ posts

While Loop and For Loop

Hmm, no support.
Alberknyis
Scratcher
1000+ posts

While Loop and For Loop

One word.

Why?

Powered by DjangoBB