[Ruby] About the difference between 2 dots and 3 dots of range object.

This is a personal memo.

About the difference between .. and...of range objects that represent consecutive numbers.

the difference

Whether to include the ending value

range object End value
.. Including
... Not included

## 2 dots In the case of two dots, the end value is included. If it is `1..3`, ** 3 is also included **.

python


for i in 1..3
  p i
end

##output
1
2
3

## 3 dots In the case of 3 dots, the end value is not included. If it is `1..3`, ** 3 is not included **.

python


for i in 1...3
  p i
end

##output
1
2

Recommended Posts

[Ruby] About the difference between 2 dots and 3 dots of range object.
[Ruby] I thought about the difference between each_with_index and each.with_index
About the difference between classes and instances in Ruby
About the difference between "(double quotation)" and "single quotation" in Ruby
About the difference between irb and pry
[Ruby] Difference between symbol variables and character string variables. About the difference between [: a] and ['a'].
[Rails / ActiveRecord] About the difference between create and create!
Explanation about Ruby Range object
About Ruby and object model
[Rails] I learned about the difference between resources and resources
[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects
[Technical memo] About the advantages and disadvantages of Ruby
[Ruby] Difference between methods with and without self in the class. About class methods and instance methods.
[Ruby] Difference between get and post
[Ruby] Difference between is_a? And instance_of?
[Ruby] Questions and verification about the number of method arguments
Understand the difference between each_with_index and each.with_index
Explanation about Array object of Ruby
The difference between programming with Ruby classes and programming without it
About the difference between gets and gets.chomp (other than line breaks)
Easy to understand the difference between Ruby instance method and class method.
Note: Difference between Ruby "p" and "puts"
Difference between isEmpty and isBlank of StringUtils
About the operation of next () and nextLine ()
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
Difference between addPanel and presentModally of FloatingPanel
[Ruby] Difference between print, puts and p
About the mechanism of the Web and HTTP
[Java] Difference between Intstream range and rangeClosed
[Rails] Difference in behavior between delegate and has_many-through in the case of one-to-one-to-many
[Ruby basics] About the role of true and break in the while statement
[Java] Understand the difference between List and Set
Think about the combination of Servlet and Ajax
Understand the difference between abstract classes and interfaces!
[Ruby] "Reference to object" and "Contents of variable"
What is the difference between SimpleDateFormat and DateTimeFormatter? ??
About next () and nextLine () of the Scanner class
The difference between puts and print in Ruby is not just the presence or absence of line breaks
Difference between member and collection of rails routes.rb
[Ruby] Difference between puts and return, output and return value
[Java] Difference between "final variable" and "immutable object"
Difference between vh and%
Difference between i ++ and ++ i
About the [ruby] operator
What is the difference between a class and a struct? ?? ??
What is the difference between System Spec and Feature Spec?
[Grails] About the setting area and the setting items of application.yml
About the relationship between HTTP methods, actions and CRUD
[Rails] What is the difference between redirect and render?
Compare the difference between dockerfile before and after docker-slim
Verification of the relationship between Docker images and containers
What is the difference between skip and pending? [RSpec]
[Ruby] Class nesting, inheritance, and the basics of self
[Rails] I investigated the difference between redirect_to and render.
About Java setters and getters. <Difference from object orientation>
What is the difference between Java EE and Jakarta EE?
[Swift] UITextField taught me the difference between nil and ""
[Java] Note about the difference between equivalence judgment and equality judgment when comparing String classes
Understand in 3 minutes! A very rough explanation of the difference between session and cookie
About the handling of Null
What is the difference between the responsibilities of the domain layer and the application layer in the onion architecture [DDD]