Please enable JavaScript to use CodeHS

CodeHS Glossary


Condition General

A condition is code that you put inside an if statement or [while loop][1]. The condition returns `true` or `false`. This allows you to "ask a question" to your code about something. ---------- Some examples of conditions in Karel are: frontIsClear() facingNorth() noBallsPresent() Examples of how to use a condition: if (noBallsPresent()) { putBall(); } while (frontIsClear()) { move(); } Common Errors: - If you forget the `()` at the end of the condition, it will always return `true`, so you need to always have the `()` - If you have a semicolon after the condition, it will not work. ---------- In Java and JavaScript, a condition can be any boolean expression. Some examples are: if (num < 10) { ... } while (ball.getY() > getHeight() && lives > 0) { ... } [1]: http://codehs.com/glossary/term/5