本文介绍了“如果"和“如果"有什么区别?带有“then"的语句在最后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我们在 if 语句的末尾放置一个 then 时,这两个 Ruby if 语句之间有什么区别?
What's the difference between these two Ruby if statements when we put a then at the end of the if statement?
if(val == "hi") then something.meth("hello") else something.meth("right") end和
if(val == "hi") something.meth("hello") else something.meth("right") end 推荐答案then 是一个分隔符,帮助 Ruby 识别条件和表达式的真实部分.
then is a delimiter to help Ruby identify the condition and the true-part of the expression.
if 条件 then true-part else false-part end
if condition then true-part else false-part end
then 是可选的除非您想在一行中编写一个 if 表达式.对于跨越多行的 if-else-end,换行符作为分隔符将条件与真实部分分开
then is optional unless you want to write an if expression in one line. For an if-else-end spanning multiple lines the newline acts as a delimiter to split the conditional from the true-part
# can't use newline as delimiter, need keywords puts if (val == 1) then '1' else 'Not 1' end # can use newline as delimiter puts if (val == 1) '1' else 'Not 1' end更多推荐
“如果"和“如果"有什么区别?带有“then"的语句在最后?
发布评论