Discuss Scratch

destroyer489
Scratcher
28 posts

Add a For loop

so I use Python, C++, and Java a lot and have the great functionality of the for-loop. this is a loop that repeats a certain number of times while having an index this is especially useful for lists and tuples. more documentation can be found here. this type of loop is incredibly useful and would be a fantastic addition to the scratch library
-Accio-
Scratcher
1000+ posts

Add a For loop

This has been suggested so many times that I can't even find an oldest duplicate.

Hi There! I'm -Accio-

But you can call me the Duplicate Destroyer

Potterhead | Ravenclaw | Forum Helper | SDS Curator | Science | Math


Check out the current SDS “Prehistoric” here:
https://scratch.mit.edu/studios/25273127/
colinmacc
Scratcher
500+ posts

Add a For loop

set [index v] to [0]
repeat (10)
change [index v] by (1)
Do things...
end

Sample Projects

ResExsention
New to Scratch
1000+ posts

Add a For loop

colinmacc wrote:

set [index v] to [0]
repeat (10)
change [index v] by (1)
Do things...
end

Uh, close, but not quite.

set [index v] to [0]
set [target v] to [whatever, even another variable]
repeat (target)
change [index v] by (1)
...
end

Semi-support though. For loops are actually quite useful.

Last edited by ResExsention (May 22, 2019 01:57:50)


Hi, I'm ResExsention, that New Scratcher who refuses to promote themself! I really do look forward to getting to know you!

If you see "[DATA EXPUNGED]", you'll know it was deleted by me. It's a lot easier.
groko13
Scratcher
100+ posts

Add a For loop

ResExsention wrote:

colinmacc wrote:

set [index v] to [0]
repeat (10)
change [index v] by (1)
Do things...
end

Uh, close, but not quite.

set [index v] to [0]
set [target v] to [whatever, even another variable]
repeat (target)
change [index v] by (1)
...
end

Semi-support though. For loops are actually quite useful.

Actually:

set [index v] to [some #]
repeat until <(index) = [some #]>
do stuff
change [index v] by some #
end

While this is a suitable workaround, I would much prefer (and fully support the addition of) for loops because they make the code neater and use a temporary variable rather than requiring a separate variable.

define (kumquat)
say [A kumquat is a small, orange, evil fruit]
say [It ate the rest of this signature. Sorry.]
MiniCoder11
Scratcher
44 posts

Add a For loop

Scratch actually already comes with a built in “for loop”. It just isn't accessible through the main editor panel. To get your hands on this incredibly useful block, just backpack it from this project: https://scratch.mit.edu/projects/343427953/.

I hope that helped!

Please let me know if there is anything else I can do to help

Weekly bulletin:
• Current Scratch 3.0 rating: | ★★★★☆ 4.0 |
PhysicsKit has been updated!
• Suggest ideas for Scratch Royale here!
Nambaseking01
Scratcher
1000+ posts

Add a For loop

Unfortunately, this seems to be a duplicate topic!

Here are all of the duplicates I found sorted from oldest to newest:

https://scratch.mit.edu/discuss/topic/11712/ (July 24, 2013)
https://scratch.mit.edu/discuss/topic/19763/ (November 7, 2013)
https://scratch.mit.edu/discuss/topic/44424/ (July 3, 2014)
https://scratch.mit.edu/discuss/topic/46758/ (July 23, 2014)
https://scratch.mit.edu/discuss/topic/81652/ (January 16, 2015)
https://scratch.mit.edu/discuss/topic/104164/ (April 3, 2015)
https://scratch.mit.edu/discuss/topic/204415/ (June 16, 2016)
https://scratch.mit.edu/discuss/topic/275054/ (August 30, 2017)
https://scratch.mit.edu/discuss/topic/305375/ (June 30, 2018)

help me edit this or u should comment “I will view all your projects” on my profile
Harakou
Scratch Team
1000+ posts

Add a For loop

Nambaseking01 wrote:

Unfortunately, this seems to be a duplicate topic!

Here are all of the duplicates I found sorted from oldest to newest:

https://scratch.mit.edu/discuss/topic/11712/ (July 24, 2013)
https://scratch.mit.edu/discuss/topic/19763/ (November 7, 2013)
https://scratch.mit.edu/discuss/topic/44424/ (July 3, 2014)
https://scratch.mit.edu/discuss/topic/46758/ (July 23, 2014)
https://scratch.mit.edu/discuss/topic/81652/ (January 16, 2015)
https://scratch.mit.edu/discuss/topic/104164/ (April 3, 2015)
https://scratch.mit.edu/discuss/topic/204415/ (June 16, 2016)
https://scratch.mit.edu/discuss/topic/275054/ (August 30, 2017)
https://scratch.mit.edu/discuss/topic/305375/ (June 30, 2018)
Yeah, there are uh, a lot of these. It's a pretty common and useful construct. I'm not quite sure why we don't have one, though I presume the idea has been floated at some point. Most likely, since it's a convenience factor, I think it was probably deemed not entirely necessary.

;

Powered by DjangoBB

Standard | Mobile