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.

Top comments (0)