Discuss Scratch

Kwaheri1025
Scratcher
77 posts

Loop variable

Besides Scratch, I also enjoy creating simple programs in Python, and in Python, the for loop (which would be the repeat () block in scratch) loops through a variable. In Python, instead of repeat (5), you would write it as:

for i in range(5):


In this case, i is a variable. In Python, you could do something like:

for i in range(5)
print i

The output of that would be:

0
1
2
3
4*

That's because the program is printing out the value of the variable, which increases once every loop.
Now in Scratch, to do that, you would have to use a workaround:

set [ looping variable v] to [0]
repeat (5)
say [ looping variable ] for (2) secs
change [ looping variable v] by (1)
end

*Note: in Python, range(x) would return all the integer values from 0 to x, NOT INCLUDING X ITSELF.
Kwaheri1025
Scratcher
77 posts

Loop variable

bump
ScriptedAwesome
Scratcher
1000+ posts

Loop variable

You already can do this.
define loop
set [i v] to [0]
repeat (5)
do something
wait (1) secs
change [i v] by (1)
end
ajskateboarder
Scratcher
1000+ posts

Loop variable

Reaction to topic getting bumped after almost 6 years
medians
Scratcher
1000+ posts

Loop variable

ajskateboarder wrote:

Reaction to topic getting bumped after almost 6 years
Wait, 2017 was 6 years ago?!??!???!
Anyway, could be useful for iterating over lists, but then you could do something like:
set [index v] to [0]
repeat (length of [list v])
change [index v] by (1)
list code ::grey
end
TerryLeeStudio
Scratcher
100+ posts

Loop variable

Here’s my implementation
Proposed Scratch version of the some syntax
Directly porting for I in range () and i is too confusing and I is short for increment and scratch is block-based where text length don’t matter. Therefore, I propose a more scratch solution
cookieclickerer33
Scratcher
1000+ posts

Loop variable

Y’all realize this is added already right?

Last edited by cookieclickerer33 (April 17, 2023 15:41:00)

Knightbot63
Scratcher
1000+ posts

Loop variable

cookieclickerer33 wrote:

(#7)
Y’all realize this is added already right?
for i in range?
cookieclickerer33
Scratcher
1000+ posts

Loop variable

Knightbot63 wrote:

cookieclickerer33 wrote:

(#7)
Y’all realize this is added already right?
for i in range?
Yea
Knightbot63
Scratcher
1000+ posts

Loop variable

cookieclickerer33 wrote:

Yea
Not repeat, are you talking about how it works when using TurboWarp or hacked blocks, or am I wrong?
cookieclickerer33
Scratcher
1000+ posts

Loop variable

Knightbot63 wrote:

cookieclickerer33 wrote:

Yea
Not repeat, are you talking about how it works when using TurboWarp or hacked blocks, or am I wrong?
Yea, it’s already added. Just harder than normal to acess. The functionality is there all that it needs is to be added to the pallet

Last edited by cookieclickerer33 (April 17, 2023 15:44:42)

Knightbot63
Scratcher
1000+ posts

Loop variable

cookieclickerer33 wrote:

(#11)
Yea, it’s already added. Just harder than normal to acess
But they mean as a real block and not the hacked blocks?
cookieclickerer33
Scratcher
1000+ posts

Loop variable

Knightbot63 wrote:

cookieclickerer33 wrote:

(#11)
Yea, it’s already added. Just harder than normal to acess
But they mean as a real block and not the hacked blocks?
I think this suggestion should be changed to adding the block into the palette, as it’s already implemented just not accessible by “normal” means

Last edited by cookieclickerer33 (April 17, 2023 15:46:25)

Knightbot63
Scratcher
1000+ posts

Loop variable

cookieclickerer33 wrote:

(#13)
I think this suggestion should be changed to adding the block into the palette, as it’s already implemented just not accessible by “normal” means
I think the OP has moved to another account so maybe they can change it??
cookieclickerer33
Scratcher
1000+ posts

Loop variable

Knightbot63 wrote:

cookieclickerer33 wrote:

(#13)
I think this suggestion should be changed to adding the block into the palette, as it’s already implemented just not accessible by “normal” means
I think the OP has moved to another account so maybe they can change it??
Wouldn’t it be better to get a mod to do it?
Knightbot63
Scratcher
1000+ posts

Loop variable

cookieclickerer33 wrote:

(#15)
Wouldn’t it be better to get a mod to do it?
Most likely.
TerryLeeStudio
Scratcher
100+ posts

Loop variable

Knightbot63 wrote:

cookieclickerer33 wrote:

(#15)
Wouldn’t it be better to get a mod to do it?
Most likely.
Here’s mine, the same idea
SciPiDilts
Scratcher
100+ posts

Loop variable

for each [my variable v] in () {
} ::control

Already a fully functional block, but they should definitely unhide it from the block palette and change the text to make it a bit clearer what it does.

Powered by DjangoBB