0Pricing
Ruby Academy · Lesson

Conditional Statements

Use if, else, elsif, and case statements to control which code executes based on conditions.

1

Conditional Statements

Conditional statements allow your Ruby programs to make decisions based on conditions.

In this lesson, you will learn how to use if, else, elsif, and case statements.

Conditional Statements — illustration 1

2

Using If and Else

The if statement executes code only if a condition is true. The else statement runs if the condition is false.

age = 18
if age >= 18
  puts 'You are an adult'
else
  puts 'You are a minor'
end

All lessons in this course

  1. Conditional Statements
  2. Loops and Iterators
  3. Logical and Comparison Operators
← Back to Ruby Academy