If Statement


Collapse Content

Until now you've programmed a series of instructions that get executed no matter what. But sometimes, you only want to do something when a certain condition is true. For example, if you're hungry, you'll eat food. Or if you're about to walk into a wall, you might change directions. When programming you're robot, you can create such conditional statements using an if block.

Guidelines

Level 6 - The if-block in this game lets you check if there's a path in a certain direction. Use this block to turn when needed!

Level 7 - Can you solve this challenge with an extra block to spare?

Level 8 - You can use more than one if-block. Can you solve this challenge with four blocks to spare?

Level 9 - Sometimes you want to take one actions when a condition is true, and otherwise do something else. For example, let's say you encounter a dangerous dragon. If you are armed, you may try to kill it, but otherwise you should probably run for your life.

Use an If-Else block to express this concept in a program. If the condition is true, it will do one thing, and otherwise it will do something else.

It's important to set the condition order carefully, since the program always checks the "if" condition first. If it's true, it will always skip the else statement.

Level 10 - this round is optional so only try it if you like very hard challenges!

The programs you wrote each solved a specific maze. When you have more experience, you can write programs that can search for a solution in any Maze!

(For example, see the Java Explorer Maze challenge.)

Contact Us
Sign in or email us at [email protected]