by David J. Malan <malan@post.harvard.edu>
Printer-Friendly Version of Tutorial

« Previous | Table of Contents | Next »

Conditions

In programming, a condition is something that must be true in order for something to happen. A condition is thus said to "evaluate to true" or "evaluate to false." In Scratch, any block whose label says "if," "when," or "until" is a sort of conditional construct.

One such block is:



The construct above is generally known as an "if construct." With it can we instruct a sprite to say hello only if, say, the user has depressed the mouse button:



A related construct is the "if-else construct":



With the above construct can we instruct a sprite to say hello or goodbye, depending on whether the user has depressed the mouse button:



Realize that these constructs can be nested to allow, for example, for three different conditions:



The above construct could be called an "if-else if-else construct".

Another conditional block is:



Yet another such block is:



Sometimes, you want one or more statements to be executed multiple times in a row. To implement this behavior, we turn our attention to loops.

« Previous | Table of Contents | Next »