Discuss Scratch
- Discussion Forums
- » Suggestions
- » Loop variable
- 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:
*Note: in Python, range(x) would return all the integer values from 0 to x, NOT INCLUDING X ITSELF.
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.
- 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
Reaction to topic getting bumped after almost 6 yearsWait, 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
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
(#7)for i in range?
Y’all realize this is added already right?
- cookieclickerer33
-
Scratcher
1000+ posts
Loop variable
Yea(#7)for i in range?
Y’all realize this is added already right?
- Knightbot63
-
Scratcher
1000+ posts
Loop variable
YeaNot repeat, are you talking about how it works when using TurboWarp or hacked blocks, or am I wrong?
- cookieclickerer33
-
Scratcher
1000+ posts
Loop variable
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 palletYeaNot repeat, are you talking about how it works when using TurboWarp or hacked blocks, or am I wrong?
Last edited by cookieclickerer33 (April 17, 2023 15:44:42)
- Knightbot63
-
Scratcher
1000+ posts
Loop variable
(#11)But they mean as a real block and not the hacked blocks?
Yea, it’s already added. Just harder than normal to acess
- cookieclickerer33
-
Scratcher
1000+ posts
Loop variable
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(#11)But they mean as a real block and not the hacked blocks?
Yea, it’s already added. Just harder than normal to acess
Last edited by cookieclickerer33 (April 17, 2023 15:46:25)
- Knightbot63
-
Scratcher
1000+ posts
Loop variable
(#13)I think the OP has moved to another account so maybe they can change it??
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
- cookieclickerer33
-
Scratcher
1000+ posts
Loop variable
Wouldn’t it be better to get a mod to do it?(#13)I think the OP has moved to another account so maybe they can change it??
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
- Knightbot63
-
Scratcher
1000+ posts
Loop variable
(#15)Most likely.
Wouldn’t it be better to get a mod to do it?
- SciPiDilts
-
Scratcher
100+ posts
Loop variable
for each [my variable v] in () {
} ::controlAlready 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.
- Discussion Forums
- » Suggestions
-
» Loop variable