ruby has all the usual control structure, such as if statements and while loops. 其它语言用括号来结束,但是ruby用end来结束。如
if count>10
puts 'try again'
elsif tries==3
puts "you lose"
else
puts "Enter a number"
end 结束符号
ruby中的大部分语句都返回一个值,这个值可以做条件。如
while line=gets
puts line.downcase
end 如果它没有到达下一个,则line=gets为false,否则为true. the assignment statement sets the variable line to either the nest line of test or nil, and then the while statement tests the value of the assignment, terminating the loop when it is nil
正文
Control Structures2007-03-15 15:41:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/daweizhao/23983.html
阅读(1775) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论