Ruby 有 if、case 和 while 表达式,它们都以通常的方式工作: >> if 2 < 3 'less' else 'more' end => "less" >> quantify = -> number { case number when 1 'one' when 2 'a couple' else 'many' end } => #<Proc (lambda)> >> quantify.call(2) => "a couple" >> quantify.call(10) => "many" >> x = 1 => 1 >> while x < 1000 x = x * 2 end => nil >> x => 1024
计算的本质——1.3 控制流
书名: 计算的本质
作者: [英] Tom Stuart
出版社: 人民邮电出版社
原作名: Understanding Computation: From Simple Machines to Impossible Programs
副标题: 深入剖析程序和计算机
译者: 张伟
出版年: 2014-11
页数: 300
定价: 69.00元
装帧: 平装
ISBN: 9787115361547