标签:times
#迭代器 5.times { puts "Hello Woeld!" } #连续输出4次Hello World! 1.upto(10) { |i| puts "The count is #{i}" } #从1数到10 10.downto(1) { |i| puts "The count is #{i}" } #从10到1 1.step(10, 2) { |i| puts "The count is #{i}" } #从1到10,步长为2 #each,使用each方法将集合内的对象逐个取出 name = ["MZD","JZM","HJT","XJP"] name.each do |x| puts x end
本文出自 “邀月乘风” 博客,请务必保留此出处http://yaoyuechengfeng.blog.51cto.com/2958475/1774799
标签:times
原文地址:http://yaoyuechengfeng.blog.51cto.com/2958475/1774799