DEV Community

Joshua Jones
Joshua Jones

Posted on

Learning Ruby: Control Flow in Ruby

IF: basically a true or false expression. When you're done you have to put END.

Else: Modify's the IF. The alternate answer to the IF statement. It shows another value.

Elseif: If you want more than 2 options

EXAMPLE:
Image description

Unless: Let's you check if something is false.
Image description

Equal or not: To check if two things are equal you use ( == ). It is a comparator (relational operator). It means is equal to
!= lets you see if two values are not equal

You can also use logical or boolean operators. Ruby has three: and (&&), or (||), and not (!). Boolean operators result in boolean values: true or false.

The boolean operator and, &&, only results in true when both expressions on either side of && are true. Here’s how && works:
Image description

OR: ( || ) is called an inclusive OR because it evaluates to true when one, or the other, or both expressions are true

NOT: boolean operator not (!). ! makes true values false, and vice-versa.

Neon image

Build better on Postgres with AI-Assisted Development Practices

Compare top AI coding tools like Cursor and Windsurf with Neon's database integration. Generate synthetic data and manage databases with natural language.

Read more →

Top comments (0)

Image of PulumiUP 2025

Explore What’s Next in DevOps, IaC, and Security

Join us for demos, and learn trends, best practices, and lessons learned in Platform Engineering & DevOps, Cloud and IaC, and Security.

Save Your Spot

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay