Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics Conditionals "elsif" and "else"

Andrew Sabato
Andrew Sabato
8,168 Points

Why is Ruby's Else if statement called elsif but in other languages its else if. (Why the wrong spelling?)

Why is Ruby's Else if statement called elsif but in other languages its else if. (Why the wrong spelling?)

3 Answers

Michael Hulet
Michael Hulet
47,912 Points

It's not wrong spelling. It's just what Ruby chose to use. It's an arbitrary decision that the language designers decided to make. That being said, it's generally just the C-style/inspired languages that use else if, which includes a broad set of languages. For example, JavaScript (a C-inspired language) uses else if, but Python (which doesn't draw much inspiration from C) uses elif. In summary, it's not wrong or anything, but it's just what Yukihiro Matsumoto (the creator of Ruby) liked best

Erika Suzuki
Erika Suzuki
20,299 Points

I know right! It's just to make the language "unique" and probably to save a few types on the keyboard. But if I'm going to choose between "elif" (Python) and "elsif" (Ruby), since both are misspelled anyway, I'd choose "elif" since it's shorter.

On a side note, you can use else if in Ruby, you just need to close it out with an end as opposed to elsif that allows you to skip the end.

See this StackOverflow question