LoginSignup
0
0

More than 5 years have passed since last update.

Ruby i++

Last updated at Posted at 2016-06-05

Rubyが i++ がない。

main.rb
i=0
while i==50
    puts i
    i++
end

これだと、
main.rb:4: syntax error, unexpected keyword_end
とエラーが出てしまいます。
そして、調べてみたら、i++は、Rubyでは使えないらしいので、

main.rb
i=0
while i==50
    puts i
    i=i+1
end

<追加>

他の書き方もあるそうです。
@844196 さん
@tamy0612 さん
ありがとうございます。

main.rb
i = 0
while i <= 50
  p i
  i += 1
end
main.rb
i = 0
while i <= 50
  p i
  i.succ
end
main.rb
50.times do |i|
  puts i
end
main.rb
1.upto(50) do |i|
  puts i
end
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0