Lesson 6 of 34
if and else: Making Decisions
8 min 25 XP
if runs code only when a condition is true; otherwise the else part runs. The condition goes inside ( ) brackets.
Example: edit me and press Run
Output Loading Java (first time takes a few seconds)
Press Run to see the result here.Comparison operators: == equal, != not equal, > greater, < less, >= greater or equal, <= less or equal. Each gives a boolean (true/false).
Example: edit me and press Run
Output Loading Java (first time takes a few seconds)
Press Run to see the result here.= stores a value, == compares. Mixing them up is one of the most common mistakes.