Discuss Scratch
- Discussion Forums
- » Suggestions
- » Why no for loops?
- DaEpikDude
-
1000+ posts
Why no for loops?
Most people who've used other programming languages probably know about for loops.
How come Scratch doesn't have them yet?
I understand you can work it around with a variable, but that applies to all languages.
Why not make it the first list C block?
Before you go and say “but there's a workaround”, that doesn't stop other languages from having them, despite being able to use while loops.
I know Scratch isn't “other languages”, but this makes it really easy to interact with everything in a list.
How come Scratch doesn't have them yet?
I understand you can work it around with a variable, but that applies to all languages.
Why not make it the first list C block?
for each (item) in [list v] {The “item” would be duplicated when you interact with it (think custom block arguments).
...
}::list //Not sure about the colour of the "item" reporter
Before you go and say “but there's a workaround”, that doesn't stop other languages from having them, despite being able to use while loops.
I know Scratch isn't “other languages”, but this makes it really easy to interact with everything in a list.
- FancyFoxy
-
500+ posts
Why no for loops?
I support this. This is one of those blocks that you will see again in other languages. Why not here?
- Wahsp
-
1000+ posts
Why no for loops?
Because America! I support this. This is one of those blocks that you will see again in other languages. Why not here?
No? Sorry
Anyway I give full support as well.
(also it's not important but when I was making the text grey I spelled it with an a because also america) I'll leave
- PkmnQ
-
1000+ posts
Why no for loops?
While it is consistent, the name isn't good. Most people who've used other programming languages probably know about for loops.
How come Scratch doesn't have them yet?
I understand you can work it around with a variable, but that applies to all languages.
Why not make it the first list C block?for each (item) in [list v] {The “item” would be duplicated when you interact with it (think custom block arguments).
...
}::list //Not sure about the colour of the "item" reporter
Before you go and say “but there's a workaround”, that doesn't stop other languages from having them, despite being able to use while loops.
I know Scratch isn't “other languages”, but this makes it really easy to interact with everything in a list.
- DaEpikDude
-
1000+ posts
Why no for loops?
What would you suggest?While it is consistent, the name isn't good. Most people who've used other programming languages probably know about for loops.
How come Scratch doesn't have them yet?
I understand you can work it around with a variable, but that applies to all languages.
Why not make it the first list C block?for each (item) in [list v] {The “item” would be duplicated when you interact with it (think custom block arguments).
...
}::list //Not sure about the colour of the "item" reporter
Before you go and say “but there's a workaround”, that doesn't stop other languages from having them, despite being able to use while loops.
I know Scratch isn't “other languages”, but this makes it really easy to interact with everything in a list.
“For” seems to make its function clear: it does something for every item in the list.
- braxbroscratcher
-
1000+ posts
Why no for loops?
set [counter v] to [0]
repeat (length of [list v] :: list)
change [counter v] by (1)
. . . :: grey // loop contents
end
(item (counter) of [list v] :: list) // use this for inputs
I don't see why we need it, the workaround's pretty easy. Once we get custom loops this would be even easier.
- Charles12310
-
1000+ posts
Why no for loops?
I don't think that's what they're talking about.set [counter v] to [0]
repeat (length of [list v] :: list)
change [counter v] by (1)
. . . :: grey // loop contents
end
(item (counter) of [list v] :: list) // use this for inputs
I don't see why we need it, the workaround's pretty easy. Once we get custom loops this would be even easier.
set [a v] to [0]
set [b v] to [0]
set [content v] to [...]
repeat (length of [list v])
change [a v] by (1)
if <(item (a) of [list v]) = (content)> then
change [b v] by (1)
end
end
repeat (b)
...
end
- braxbroscratcher
-
1000+ posts
Why no for loops?
he's talking about a for loop and a reporter that yields an item of a list based upon the iteration. It's really easy.I don't think that's what they're talking about.set [counter v] to [0]
repeat (length of [list v] :: list)
change [counter v] by (1)
. . . :: grey // loop contents
end
(item (counter) of [list v] :: list) // use this for inputs
I don't see why we need it, the workaround's pretty easy. Once we get custom loops this would be even easier.set [a v] to [0]
set [b v] to [0]
set [content v] to [...]
repeat (length of [list v])
change [a v] by (1)
if <(item (a) of [list v]) = (content)> then
change [b v] by (1)
end
end
repeat (b)
...
end
- DaEpikDude
-
1000+ posts
Why no for loops?
Yes, I know there is an easy workaround, but my reasoning is that for loops exist in some form in basically every language. Why don't they exist in Scratch?set [counter v] to [0]
repeat (length of [list v] :: list)
change [counter v] by (1)
. . . :: grey // loop contents
end
(item (counter) of [list v] :: list) // use this for inputs
I don't see why we need it, the workaround's pretty easy. Once we get custom loops this would be even easier.
- braxbroscratcher
-
1000+ posts
Why no for loops?
For loops are technically ourYes, I know there is an easy workaround, but my reasoning is that for loops exist in some form in basically every language. Why don't they exist in Scratch?set [counter v] to [0]
repeat (length of [list v] :: list)
change [counter v] by (1)
. . . :: grey // loop contents
end
(item (counter) of [list v] :: list) // use this for inputs
I don't see why we need it, the workaround's pretty easy. Once we get custom loops this would be even easier.
repeat ()loops as all a for loop does is repeat for X number of times. It's the i (iteration) counter that allows you to act on specific items of lists. Sure, this may be hidden in some languages inside the function, but I don't think the workaround is too hard to do, especially since it lets you understand how for loops work.
end
- Ferociousfeind
-
100+ posts
Why no for loops?
Full support, though the name “for (item) in (list)” is somewhat unclear and not in Scratch's “it reads like an actually grammatically correct sentence!” like "if <> then“, ”touching ( v)?“, ”ask () and wait“, these all tell you exactly what they do, while ”for (item) in (list)" just doesn't. Perhaps something like
would work better
repeat every (item) in [list v] {
. . . :: tips
} :: list
would work better
- -Rex-
-
500+ posts
Why no for loops?
What about
repeat through [list v] with (var :: control) as each item {
...
} :: control
Last edited by -Rex- (Sept. 7, 2017 01:40:13)
- Charles12310
-
1000+ posts
Why no for loops?
then“, ”touching ( v)?“, ”ask () and wait“, these all tell you exactly what they do, while ”for (item) in (list)" just doesn't. Perhaps something likeOther languages use “for every () in ()”. Full support, though the name “for (item) in (list)” is somewhat unclear and not in Scratch's “it reads like an actually grammatically correct sentence!” like "if <>repeat every (item) in [list v] {
. . . :: tips
} :: list
would work better
- -Rex-
-
500+ posts
Why no for loops?
Scratch is meant to be easier to understand than other languages. While a for loop would be nice, the name of the block would have to be changed to something more easily understandable.Other languages use “for every () in ()”. …
- DaEpikDude
-
1000+ posts
Why no for loops?
I like that wording, yeah. That's good! What aboutrepeat through [list v] with (var :: control) as each item {
...
} :: control
- kenny2scratch
-
500+ posts
Why no for loops?
Meh, I know the feeling…
and yet then there's
and yet then there's
set [i v] to [0]
repeat (length of [list v])
change [i v] by (1)
set [var v] to (item (i) of [list v])
...
end
- TimeLordPlanet
-
500+ posts
Why no for loops?
Support here! When I was in Python, I was super confused as to what a for loop was due to lack of corresponding Scratch Blocks,
- Za-Chary
-
1000+ posts
Why no for loops?
It looks like this is a duplicate topic of this one over here, so I’ll close this thread to keep the conversation all in one place.
Feel free to continue the discussion in the link provided above.
Feel free to continue the discussion in the link provided above.
- Discussion Forums
- » Suggestions
-
» Why no for loops?