Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does 'elseif' still exist? [closed]

I'm just learning ROR and I came across the if / else statements. I also came across 'elseif' but my text editor (textmate) doesn't pick it up as a keyword, nor does the program run properly.

if name == 'Chris'   puts 'What a lovely name.' elseif name == 'Katy'   puts 'What a lovely name!' end 

I'm using the book Learn to Program, which was written several years ago. I was wondering if the 'elseif' was changed because, when I simply use 'else', it seems to function properly.

like image 595
catchmikey Avatar asked Nov 25 '12 11:11

catchmikey


People also ask

Can we use else if after else?

It only has if (expression) statement else statement . Because an if statement is a statement (obviously), you can use it after else , just like any other statement, like for or empty ; or switch or any arbitrary expression statement.

Does else if execute after if?

The if/else statement With the if statement, a program will execute the true code block or do nothing. With the if/else statement, the program will execute either the true code block or the false code block so something is always executed with an if/else statement.

What is Elseif?

elseif , as its name suggests, is a combination of if and else . Like else , it extends an if statement to execute a different statement in case the original if expression evaluates to false .

What is the point of ELSE IF?

The if-else statement is used to execute both the true part and the false part of a given condition. If the condition is true, the if block code is executed and if the condition is false, the else block code is executed.


2 Answers

It's elsif, not elseif.

Slightly confusing when you're new, probably.

like image 188
s.m. Avatar answered Sep 24 '22 20:09

s.m.


Try with elsif (no second e).

Source

like image 22
alex Avatar answered Sep 22 '22 20:09

alex