Conditional Statements
Use if, else, elsif, and case statements to control which code executes based on conditions.
Conditional Statements is a free Ruby Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ruby Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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.

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'
end3
Using Elsif
The elsif statement allows multiple conditions to be checked.
score = 85
if score >= 90
puts 'Grade: A'
elsif score >= 80
puts 'Grade: B'
else
puts 'Grade: C or lower'
end4
Using Case Statements
The case statement is a cleaner way to handle multiple conditions.
day = 'Monday'
case day
when 'Monday'
puts 'Start of the week'
when 'Friday'
puts 'Weekend is near!'
else
puts 'Another day!'
end5
Using the Ternary Operator
The ternary operator is a shorthand way of writing if-else statements.
age = 20
puts age >= 18 ? 'Adult' : 'Minor'6
Using Unless
The unless statement runs code only if the condition is false.
temperature = 10
unless temperature > 20
puts 'It is cold outside!'
end7
Using Logical Operators with If
Logical operators like && (and) and || (or) can be used with if statements.
age = 25
has_id = true
if age >= 18 && has_id
puts 'You can enter!'
end8
9
Using Nested If Statements
Nested if statements allow you to check multiple conditions inside each other.
score = 95
if score >= 90
if score >= 95
puts 'Excellent!'
else
puts 'Great job!'
end
end10
Congratulations!
You have learned how to use conditional statements in Ruby.
Next, you will learn about loops and iterators.

Frequently asked questions
Is the “Conditional Statements” lesson free?
Yes — the full text of “Conditional Statements” is free to read here on the web, and the Ruby Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ruby Academy course, upgrade to CoddyKit PRO.
What will I learn in “Conditional Statements”?
Use if, else, elsif, and case statements to control which code executes based on conditions. You practise Ruby Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Ruby Academy?
No prior experience is required. Ruby Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Conditional Statements” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Ruby Academy lesson?
Yes. Every Ruby Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Conditional Statements
- Loops and Iterators
- Logical and Comparison Operators