Discuss Scratch

LOLScratch12233
Scratcher
100+ posts

For Loop

TheHockeyist wrote:

They're saying that if something is true, then do it.

That's like the if block shown below.

if <(condition) = [true]> then

end

TheHockeyist wrote:

They're saying that if something is true, then do it.

That's like the if block shown below.

if <(condition) = [true]> then
do something
end

kccuber
Scratcher
1000+ posts

For Loop

would it look like this?
for each [foo v] in (3) {
...
} :: control
or this?
for (foo) = (2) to (7) {
...
} :: control // you would be able to drag out the (foo)
and for good measure, why not this too?
for (item) in [list v] {
...
} :: list
han614698
Scratcher
1000+ posts

For Loop

edit bump
medians
Scratcher
1000+ posts

For Loop

like this:
for(let i = 0; i < 4; i++ //would do i = i + 1) {
console.log(i);
}
would log in this order:
0
1
2
3
for(let i = 4; i > 0; i– //would do i = i - 1) {
console.log(i);
}
would log in this order:
4
3
2
1
for(let i = 0; i < 4; i += 2 //would do i = i + 2) {
console.log(i);
}
would log in this order:
0
2
for(let i = 4; i > 0; i -= 2 //would do i = i - 2) {
console.log(i);
}
would log in this order:
4
2
mumu245
Scratcher
1000+ posts

For Loop

gdpr533f604550b2f20900645890 wrote:

Both of you misunderstand the suggestion. A for loop is a loop which executes the body a certain amount of times, incrementing a variable after each iteration.
for(var i = 0; i < 10; i++) {
}

A variable called i is initialized to 0 when the loop is entered. Before each iteration, the interpreter checks if i is less than 10. If the condition is false, the loop is stopped. After each iteration, i is incremented.

However, the OP mentions lists, and not creating variables, so I assume that they want for-each loops. These are similar to for-loops, but instead of using a counter variable, they execute the body “for each” element in the array.

I support this suggestion.

EDIT: I was ninja'd by MathlyCat, who also seems to misunderstand the suggestion.
True.

Also, this is already implemented, but hidden.
for each [ v] in (){
} ::control

Last edited by mumu245 (Sept. 23, 2021 12:45:53)

LOLScratch12233
Scratcher
100+ posts

For Loop

I have loop blocks:
forever

end
while<>{
}::control

for each [foo v] in (10){
}::control
SuperMarioHome
Scratcher
100+ posts

For Loop

Workaround

set [i v] to (0)
repeat (. . . :: grey)
. . .
change [i v] by (1)
end
dave-alt-4
Scratcher
1000+ posts

For Loop

for loop? like (qbasic)
a = 1
FOR a = 1 TO 5
PRINT a
NEXT a
isn't that doable with
set [a v] to [1]
repeat until (not <(a) < [6]> )
say [a]
change [a] by (1)
-EmeraldThunder-
Scratcher
1000+ posts

For Loop

dave-alt-4 wrote:

isn't that doable with
Technically yes but it's a hassle to create the variables and also feels a little bit clumsy with having to increment the variable yourself every time. A for loop would be so much neater.
dave-alt-4
Scratcher
1000+ posts

For Loop

uSe CuStOm BlOcKs no support support since new scratchers probably don't know how to use custom blocks

Last edited by dave-alt-4 (Nov. 29, 2021 06:43:37)

historical_supa
Scratcher
1000+ posts

For Loop

support, this would make scrolling projects and lots of others more simpler
I_LOVE_TO_MAKE_STUFF
Scratcher
1000+ posts

For Loop

So:
for (i) in () {
}:: control
Right?
ideapad-320
Scratcher
1000+ posts

For Loop

it would be
repeat () times{
...
}storing the loop number in[my variable v]::control
VeryFamus
Scratcher
1000+ posts

For Loop

ideapad-320 wrote:

it would be
repeat () times{
...
}storing the loop number in[my variable v]::control
That seems like a very oversized C block.

And, I might be wrong, but this suggestion seems to be wanting to add a block that does this:
repeat (insert variable)

end
But, seeing as how it’s in the block palette, just hidden, this doesn’t seem like it would be a very bad thing to add.
jackson49
Scratcher
1000+ posts

For Loop

Bump
ScolderCreations
Scratcher
1000+ posts

For Loop

I am absolutely astounded. Just amazing. I cannot believe this topic survived so many years despite the fact that it already exists. That's right, scratch already has a for loop that includes variables. However, it's hidden from the block pallette, which basically means you can't find it unless someone makes a project including it. Therefore, if the suggestion means just add the block back to the list, then yeah, I support.
RediblesQW_Doors
Scratcher
38 posts

For Loop

gdpr533f604550b2f20900645890 wrote:

Both of you misunderstand the suggestion. A for loop is a loop which executes the body a certain amount of times, incrementing a variable after each iteration.
for(var i = 0; i < 10; i++) {
}

A variable called i is initialized to 0 when the loop is entered. Before each iteration, the interpreter checks if i is less than 10. If the condition is false, the loop is stopped. After each iteration, i is incremented.

However, the OP mentions lists, and not creating variables, so I assume that they want for-each loops. These are similar to for-loops, but instead of using a counter variable, they execute the body “for each” element in the array.

I support this suggestion.

EDIT: I was ninja'd by MathlyCat, who also seems to misunderstand the suggestion.
k
cookieclickerer33
Scratcher
1000+ posts

For Loop

it shouldnt use =

the = isnt a math equal to like 5 = 5
in js and python the = is how you define/set a variable so what it really is saying is

for each (var) set var to (1) to (10)

is not
for each (var) equal to (1) to (10)

its really

for each (number) in (1) to (10)

i see the = being used incorrectly in mods that have this block because they think it means the former

so the block should be called
set [var v] for each num in (1) to (10){

}::control

Powered by DjangoBB