Ruby If, Else If Command Syntax紅寶石如果,否則如果命令語法
The Ruby language has a very simple control structure that is easy to read and follow. Ruby語言有一個很簡單的控制結構,易於閱讀和遵循。
If syntax 如果語法
if var == 10如果var == 10
print “Variable is 10″打印“變量是10”
end末端
If Else Syntax 如果拍賣品語法
if var == 10如果var == 10
print “Variable is 10″打印“變量是10”
else其他的
print “Variable is something else”印刷版“變是另外一回事”
end末端
If Else If Syntax 如果拍賣品如果語法
Here's the key difference between Ruby and most other languages.這裡的關鍵區別紅寶石和大多數其他語言。 Note that “else if” is actually spelled “elsif” without the e.請注意,“否則,如果”實際上是拼寫“elsif”,不包括大腸桿菌
if var == 10如果var == 10
print “Variable is 10″打印“變量是10”
elsif var == “20″ elsif無功==“20”
print “Variable is 20″打印“變量是20”
else其他的
print “Variable is something else”印刷版“變是另外一回事”
end末端
Ternary (shortened if statement) Syntax 三元(縮短if語句)語法
Ternary syntax is the same in Ruby as most languages.三元語法是相同的,因為大多數的Ruby語言。 The following sample will print “The variable is 10″ if var is equal to 10.下面的示例將打印“這個變量是10”如果var等於10。 Otherwise it will print “The variable is Not 10″.否則,將打印“這個變量是不是10”。
print “The variable is ” + (var == 10 ? “10″ : “Not 10″)印刷版“的變量是”+(無功== 10?“10”:“不是10”)

Daily Email Updates每日電子郵件更新
You can get our how-to articles in your inbox each day for free.你可以得到我們的指導性文章在您的收件箱每天免費。 Just enter your name and email below:只要輸入您的姓名和電子郵件如下:


