ruby学习_2

来源:互联网 发布:网络调研平台 编辑:程序博客网 时间:2024/06/10 12:41
=begin变量:局部变量:以小写字母或者'_'起始的变量全局变量:以‘$’起始的变量实例变量:以'@'起始的变量类变量:  以'@@'起始的变量虚拟变量:”true“,"false","self"等特定名称的变量unless语句:unless condition thenactend与if相反etc.->a = 10  b = 20  unless a > b    puts "execute here!"  end    output:  execute here!case 语句:case 比较的对象when value1 thenact1when value2 then    act2elseact3enduntil 语句:sum = 0i = 1 until sum >= 50sum+=ii += 1 end=endi = 0['gao','shang','bo','for','test'].each{|str|  i += 1  if(i == 3)    break  end  p [i,str]}#another sample=begin  continue ?=endi = 0['gao','shang','bo','for','test'].each{|str|  i += 1  if(i == 3)    next  end  p [i,str]}#the third sample=begin  redo 再次执行当前语句,即执行i += 1=endi = 0['gao','shang','bo','for','test'].each{|str|  i += 1  if(i == 3)    redo  end  p [i,str]}

0 0