1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Ruby】rangeオブジェクトのドット2つとドット3つの違いについて。

Posted at

個人メモです。

連続した数値を表すrangeオブジェクトの.....の違いについて。

##違い
終わりの値を含むかどうか

rangeオブジェクト 終わりの値
.. 含む
... 含まない

##ドット2つ ドット2つの場合は終わりの値を含む。 `1..3`とすれば**3も含む**。
for i in 1..3
  p i
end

##出力
1
2
3

##ドット3つ ドット3つの場合は終わりの値を含まない。 `1..3`とすれば**3を含まない**。
for i in 1...3
  p i
end

##出力
1
2
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?