Ruby: What does the keyword "in" mean

When I find the keyword "in" in ruby ​​for the first time. I think maybe I can do this: 1 at (0.10) But it looks like I can't use it that way.

Then I look at it on ruby-lang.org and google. No answer!

What does the in keyword in ruby ​​mean?

+6
ruby
source share
2 answers

You should be able to do the following:

for i in 0..10 do puts i end 

The expression 1 in (0..10) that you mentioned will not work, because the constant (1) cannot change in the range - it is a constant! You need to specify the variable before the in keyword.

Hope this helps.

See this page .

+6
source share

according to pragmatic programs, you can write this as

 while *name*[, *name*]... in *expression* [do | :] body end 

for you to use it in cycles, sorry if this is vague, but I just started to study ruby.

0
source share

All Articles