热门IT资讯网

Ruby-迭代器

发表于:2024-11-24 作者:热门IT资讯网编辑
编辑最后更新 2024年11月24日,#迭代器5.times { puts "Hello Woeld!" } #连续输出4次Hello World!1.upto(10) { |i| puts "The count is #{i}" }
#迭代器5.times { puts "Hello Woeld!"  }  #连续输出4次Hello World!1.upto(10) { |i| puts "The count is #{i}" }   #从1数到1010.downto(1) { |i| puts "The count is #{i}"  }    #从10到11.step(10, 2) { |i| puts "The count is #{i}"  }   #从1到10,步长为2#each,使用each方法将集合内的对象逐个取出name = ["MZD","JZM","HJT","XJP"]name.each do |x|  puts xend


0