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.downcaseend 如果它没有到达下一个,则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

评论