This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-05-04 10:00:20

taconerd
New Scratcher
Registered: 2013-01-12
Posts: 3

How to make a for loop in scratch

Here's how to make a for loop in scratch:
You need your list and two variables. Variable a and variable b. And your list, c.
Here's the code:

set [a v] to [0]
repeat until < (a)>(length of c) >
    change [a v] by [1]
    set [b v] to (item(a) of c)
end
After that last line inside the "repeat until" yo can do whatever you want with variable b, which is item (a) of list c. You can use this to delete all the zeros in a list for example by adding this code:
if < (b)=[0] >
    delete (a) of c

Offline

 

#2 2013-05-04 10:04:02

taconerd
New Scratcher
Registered: 2013-01-12
Posts: 3

Re: How to make a for loop in scratch

Here's how to make a for loop in scratch:
You need your list and two variables. Variable a and variable b. And your list, c.
Here's the code:

set [a v] to [0]
repeat until < (a)>length of c >
    change [a v] by [1]
    set [b v] to item(a) of c
end
After that last line inside the "repeat until" yo can do whatever you want with variable b, which is item (a) of list c. You can use this to delete all the zeros in a list for example by adding this code:
if < (b)=[0] >
    delete (a) of c

Offline

 

#3 2013-05-04 10:07:42

taconerd
New Scratcher
Registered: 2013-01-12
Posts: 3

Re: How to make a for loop in scratch

Both of these posts have faulty scratchblocks. Disregard both of them.

Offline

 

Board footer