Reference

Video Lessons

Learning Objectives

repeat, if and ifelse

Review

By now, you've used at least a couple of commands that like instruction lists as input, like everyone and forever. For example, you might have used something like:

forever [fd 5 wait 1]
everyone [seth 0 clickon]

You know that an instruction is a command together with its inputs (if any), and an instruction list is a list of instructions. For example, the instruction list [seth 0 clickon] has two instructions: seth 0 and clickon.

In the Procedures Tab, Returns are treated as spaces, so you can write procedures like this:

to start
forever [
  fd 5
  setshape remainder 4 sum shape 1
  wait 1
]
end

In the Command Center, you can't have lists that start on one line and end on another, but in procedures it's OK. You could also write something like this:

to go
everyone
[seth 0 clickon]
end

Repeat

There is another useful command that likes an instruction list as one of its inputs. The repeat command need two inputs. For the first input, repeat likes a number. For the second input, repeat likes an instruction list. The repeat command

repeat 4 [fd 50 rt 90]

runs the instructions in the instruction list [fd 50 rt 90] four times.

If

Like the repeat command, the if command also needs two inputs and likes an instruction list as its second input. For its first input, it likes "true or "false. If the first input is "true, if runs the instruction list. If the first input is "false, it doesn't run the instruction list.

Ifelse

The ifelse command needs three inputs. Like if, it likes "true or "false as its first input. It likes an instruction list for the second input and an instruction list for the third input. Like if, if the first input is "true, ifelse runs the instruction list given as the second input. If the first input is "false, ifelse runs the instruction list given as the third input.

About the Center for Talent Development

Center for Talent Development (CTD), housed at Northwestern University's School of Education and Social Policy, is an accredited learning center and research facility that identifies, educates and supports gifted students and their families and serves as a leader in gifted education. Learn more about the Center for Talent Development.