Ruby-on-rails “elseif”还存在吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13550407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:04:49  来源:igfitidea点击:

Does 'elseif' still exist?

ruby-on-railsrubyif-statement

提问by catchmikey

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.

我只是在学习 ROR 并且遇到了 if / else 语句。我也遇到过 'elseif',但我的文本编辑器 (textmate) 没有将它作为关键字选择,程序也不能正常运行。

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.

我正在使用几年前写的《学习编程》这本书。我想知道“elseif”是否已更改,因为当我简单地使用“else”时,它似乎可以正常运行。

回答by s.m.

It's elsif, not elseif.

elsif,不是elseif

Slightly confusing when you're new, probably.

当你是新手时,可能会有点混乱。

回答by alex

Try with elsif(no second e).

尝试使用elsif(no second e)。

Source

来源