Discuss Scratch

Extremguy
Scratcher
100+ posts

For Loop

Scratch team should definitly add these loop and lemme explain. I know there are aleardy the “Repeat (number) of times” or repeat until stuff is done , but I think that we need the implementation of a for loop , because we wont need to have all time to create new freaking variable to check a list. So list handling will be way more easier within' a good ol' for loop. Please add for loop that have their own variable inside like for example

for myVariable(of the loop no need to create a new one on the side) = 2 do
stuff
end
DownsGameClub
Scratcher
1000+ posts

For Loop

Wouldn't this be sort of like the
forever

end
block?

I find this opening way too confusing. What is your suggestion? Loops do have to stop at some point.

Last edited by DownsGameClub (June 16, 2016 19:00:40)

TheHockeyist
Scratcher
1000+ posts

For Loop

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

MathlyCat
Scratcher
1000+ posts

For Loop

I'd like to point something out:

forever

if <(this) = [1 ]> then

end

end

Since it's a forever loop around the if block it will execute the provided is true (or just use a repeat until not combo)
For loops wouldn't add very much into Scratch in the first place due to it's functions being usuable through other blocks; workarounds.

No support.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

For Loop

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.

Last edited by gdpr533f604550b2f20900645890 (June 16, 2016 19:14:27)

Extremguy
Scratcher
100+ posts

For Loop

It not forever and if m'kay. I dont know why you people are integreating if condition inside of your script , because do you know what is a for loop. With a for loop I can check condition by using lists without condition (I'm sorry if it sound complicated)

for example I have a list named to condition

and in that list I have some condition that need to be met by other list

so I have my list that are like a list of stuff that need to match the condition list
and then my for loop will trigger through the list to see if the condition match using a block.

TheHockeyist
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. This is similar to a for-loop, but instead of using a counter variable, executes 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.

That would just be repeat x times, increasing i by one each time until i = x.

We can already do that; no support.

Last edited by Paddle2See (April 21, 2021 21:19:37)

gdpr533f604550b2f20900645890
Scratcher
1000+ posts

For Loop

Extremguy wrote:

It not forever and if m'kay. I dont know why you people are integreating if condition inside of your script , because do you know what is a for loop. With a for loop I can check condition by using lists without condition (I'm sorry if it sound complicated)

for example I have a list named to condition

and in that list I have some condition that need to be met by other list

so I have my list that are like a list of stuff that need to match the condition list
and then my for loop will trigger through the list to see if the condition match using a block.

Is “iterate” the word that you are looking for?

These aren't the droids you're looking for. :P
MathlyCat
Scratcher
1000+ posts

For Loop

Extremguy wrote:

It not forever and if m'kay. I dont know why you people are integreating if condition inside of your script , because do you know what is a for loop. With a for loop I can check condition by using lists without condition (I'm sorry if it sound complicated)

for example I have a list named to condition

and in that list I have some condition that need to be met by other list

so I have my list that are like a list of stuff that need to match the condition list
and then my for loop will trigger through the list to see if the condition match using a block.

I myself like for loops but haven't used one in a while; also don't complain at us, I read your suggestion, no offense, but it was poorly explained.

Chibi, I was thinking of that but absolutely forgot the variable part; assuming it's crucial to the for loop.

Support.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

For Loop

TheHockeyist wrote:

That would just be repeat x times, increasing i by one each time until i = x.

We can already do that; no support.
Sorry, but I beg to differ. Scratch has a serious variable cluttering problem due to a lack of script and loop scopes. The OP mentions the annoyance of littering the blocks palette with variables. Many languages have for-each loops for iterating over arrays.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

For Loop

MathlyCat wrote:

I myself like for loops but haven't used one in a while; also don't complain at us, I read your suggestion, no offense, but it was poorly explained.

Chibi, I was thinking of that but absolutely forgot the variable part; assuming it's crucial to the for loop.

Support.
Based on the description, I believe that the OP actually wants for-each loops. They mention the problem which exists about creating variables in Scratch, and for-loops still use variables.
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

For Loop

Is this what you want?
for each (item) in [list v]::cstart control

end
The item variable is an upvar which can be dragged.
Extremguy
Scratcher
100+ posts

For Loop

People who disagree ,when you will do some project containing lots of list and lots variable you will understand that it really annoying to have ten thousand billionth of freaking global/sprite variable in your variable list because of dem freaking loop. When you are checking the element of a list you need a variable to check all of them one by one and it wont do itself just with this block:

repeat ()  
end

It's because we need a variable to check in all because there are no for loop. Go see my project and you will understand what I mean by messy variable . We need for loop.

Here's a basic example of a loop without the for that have to check all the stuff
https://scratch-mit-edu.ezproxyberklee.flo.org/projects/113789736/

In other language , when you have a for loop the new var inside of the for loop is hold by the for loop and there wont have to be a new var set in your top area where you set your var.
Mmaarten
Scratcher
100+ posts

For Loop

No support
gdpr533f604550b2f20900645890
Scratcher
1000+ posts

For Loop

I support loops such as for and for-each, with upvars. I would also like script and loop scopes for variables.

Mmaarten wrote:

No support
Please be constructive and say why you don't support.

Last edited by gdpr533f604550b2f20900645890 (June 16, 2016 19:24:55)

MathlyCat
Scratcher
1000+ posts

For Loop

Mmaarten wrote:

No support
A useful resource for you to use would be:

This should be read before making a reply on this forum

Thanks,
DownsGameClub
Scratcher
1000+ posts

For Loop

Oh, so you are suggesting a
For <>:: Control

end
block?
(Supposed to be a loop…)

Last edited by DownsGameClub (June 16, 2016 19:58:34)

Sigton
Scratcher
1000+ posts

For Loop

For anyone who has used a text-based language properly, you'll know how useful for loops are
For example, if I was to have the following python code:
my_array = [
    item1,
    item2,
    item3,
    item4
    ]
for item in my_array:
    print(item)
    # item would equal "item1" on first iteration, "item2" on second iteration and so on.
Then the output would be this:
>>> item1
>>> item2
>>> item3
>>> item4
>>>
So you see how useful they are. I give full support.

Sigton

EDIT: I thought I'd show what it would be like without for loops.
my_array = [
    item1,
    item2,
    item3,
    item4
    ]
n = 0
while n < len(my_array):
    print(my_array[n])
    n += 1
    # n is increased by 1 every iteration, and then prints item n of my array

Last edited by Sigton (June 16, 2016 20:13:44)

DownsGameClub
Scratcher
1000+ posts

For Loop

Ahhh…

IS that what you are suggesting OP?
Extremguy
Scratcher
100+ posts

For Loop

yeah I was suggesting the addon of that kind of loop.

Powered by DjangoBB