Learning Ruby: Control Flow in Ruby
Joshua Jones
Posted on January 29, 2024
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
Unless: Let's you check if something is false.
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:
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.
Posted on January 29, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024