Discuss Scratch

DaEpikDude
Scratcher
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?
for each (item) in [list v] {
...
}::list //Not sure about the colour of the "item" reporter
The “item” would be duplicated when you interact with it (think custom block arguments).
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
Scratcher
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
Scratcher
1000+ posts

Why no for loops?

FancyFoxy wrote:

I support this. This is one of those blocks that you will see again in other languages. Why not here?
Because America!
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
Scratcher
1000+ posts

Why no for loops?

DaEpikDude wrote:

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] {
...
}::list //Not sure about the colour of the "item" reporter
The “item” would be duplicated when you interact with it (think custom block arguments).
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.
While it is consistent, the name isn't good.
DaEpikDude
Scratcher
1000+ posts

Why no for loops?

PkmnQ wrote:

DaEpikDude wrote:

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] {
...
}::list //Not sure about the colour of the "item" reporter
The “item” would be duplicated when you interact with it (think custom block arguments).
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.
While it is consistent, the name isn't good.
What would you suggest?
“For” seems to make its function clear: it does something for every item in the list.
braxbroscratcher
Scratcher
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
Scratcher
1000+ posts

Why no for loops?

braxbroscratcher wrote:

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.
I don't think that's what they're talking about.

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
Scratcher
1000+ posts

Why no for loops?

Charles12310 wrote:

braxbroscratcher wrote:

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.
I don't think that's what they're talking about.

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
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.
DaEpikDude
Scratcher
1000+ posts

Why no for loops?

braxbroscratcher wrote:

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.
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?
braxbroscratcher
Scratcher
1000+ posts

Why no for loops?

DaEpikDude wrote:

braxbroscratcher wrote:

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.
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?
For loops are technically our
repeat ()

end
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.
Ferociousfeind
Scratcher
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

repeat every (item) in [list v] {
. . . :: tips
} :: list

would work better
-Rex-
Scratcher
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
Scratcher
1000+ posts

Why no for loops?

Ferociousfeind wrote:

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

repeat every (item) in [list v] {
. . . :: tips
} :: list

would work better
Other languages use “for every () in ()”.
-Rex-
Scratcher
500+ posts

Why no for loops?

Charles12310 wrote:

Ferociousfeind wrote:

Other languages use “for every () in ()”.
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.
DaEpikDude
Scratcher
1000+ posts

Why no for loops?

-Rex- wrote:

What about
repeat through [list v] with (var :: control) as each item {
...
} :: control
I like that wording, yeah. That's good!
kenny2scratch
Scratcher
500+ posts

Why no for loops?

Meh, I know the feeling…
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
Scratcher
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
Scratcher
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.

Powered by DjangoBB