If , elsif, else, end. ruby

Madiwa Simon
2 min readJun 6, 2021

--

simple way to learn or remember the if statements in ruby.

IF STATEMENT. If the statement you put in is true it will run the code you want your program to run. If the verification of the statement is false it won’t run the following code associated with the if statement.

this will execute puts “b is greater than a” because the statement is true
this will not execute puts “b is greater than a” because the statement is false and will end your program.

ELSIF STATEMENT. After checking the IF statement and it comes out false then the elsif will come into play checking elsif is true. If elsif is true same goes to the code it will run the program associated with the elsif statement.

this will execute puts “b is greater than a” because the if statement is false and will check your elsif statement which is true.

ELSE STATEMENT. most likely your else statement will be empty right after else because this will be the last one you would like to run after checking your if and elsif. It will simply run whatever you put in the else statement if your if and elsif are both false.

this will run because both if and elsif are false.

You can put any number of if and elsif until it is done checking all the statements you put in. It will END the code.

Hope this will help you remember and learn in a simpler way.

--

--

No responses yet