Learn creative coding writing simple programs

12. Do a loop animation using an if() statement

In this episode we learn how we can use the if() statement to execute some code conditionally. That means the code is not executed always, but only if certain condition is met. In our example, the condition is that the circle has moved too far to the right. In that case, we bring the circle back to the left border of the screen.
We also see how to animate two objects at different speeds, and how each object can have a different color.

Tags: loop, conditional, if

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
  Do `float` and `int` smell similar?
To highlight code blocks, use ```processing and ``` like this:
  ```processing
  void setup() {
    size(600, 600);
  }
  ```