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. This is lesson 1 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Ruby Academy learning path, and your progress syncs across the web and the CoddyKit app. The Ruby Academy course includes 3 lessons in total.
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.

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'
endUsing 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'
endUsing 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!'
endUsing the Ternary Operator
The ternary operator is a shorthand way of writing if-else statements.
age = 20
puts age >= 18 ? 'Adult' : 'Minor'Using Unless
The unless statement runs code only if the condition is false.
temperature = 10
unless temperature > 20
puts 'It is cold outside!'
endUsing 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!'
endUsing 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
endCongratulations!
You have learned how to use conditional statements in Ruby.
Next, you will learn about loops and iterators.

Learn Ruby with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 29
- Lessons
- 109
Frequently Asked Questions
Is the “Conditional Statements” lesson free?
Yes — any 3 lessons of the Ruby Academy learning path, including “Conditional Statements”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Ruby Academy course includes 3 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.
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