-3

在下面的代码中,我放置了一个救援子句。但我无法追查为什么end他们之间会发生冲突。你能帮我找出原因吗?为什么会这样?

代码:

n=1
until n > 4 do
  begin
    1/0
    (1..4).each do |l|
      if 'B' == 'B'
        if 1 != 0
          p 'dog'  
        end
      end
      if 'A' == 'A'
        if 1 != 0
          p 'cat'
        end
      end
    end     
    If true == true
      p 'hi'
    end
  rescue
    p 'exception' 
  end
  n=n+1  
end

错误:

E:/WIPData/Ruby/Scripts/test.rb:64: syntax error, unexpected keyword_rescue, exp
ecting keyword_end
E:/WIPData/Ruby/Scripts/test.rb:71: syntax error, unexpected keyword_end, expect
ing $end
4

1 回答 1

2
If true == true

Pascal 大小写If不是有效的 ruby​​ 关键字。因此,它end改为匹配另一个开始关键字。

于 2013-01-28T08:01:22.533 回答