Well, I have a problem in Ruby about array and iterating. I'm a noob. Let's get to the point. Here's the problem :
- I have an array, let's say the name is myary = []
- myary contains 25 integer data from index 1 - 25, those are integer 1 - 25. index 0 is nil.
- I have a variable, let's say the name is myvar( I don't know the value of this variable).
Then I have this code
puts "I can do that"
Now here goes the task : puts "I can do that" will be executed only if myvar's value is not 1,2,3 and so on until 25. The question is how do I check the value of myvar ? And also how to give the order to execute puts "I can do that" if the value of myvar is not between 1 and 25. I might try it like this :
puts "I can do that" if myvar != 1 || myvar != 2 || myvar != 3 # and so on until myvar != 25
But I believe that is ridiculous way, if I need to check until 100 then I will be damned. Perhaps there an elegant way to do this. And perhaps someone can help a noob like me.
I hope I explain it clearly because I myself is a little confused with this damn task. Thank you very much all.
EDIT : Ahh umm sorry for not mention it earlier I just figure out something that bothered me, I notice that if myvar is a float between 1 - 25 it should not execute the code "I can do that". Now this drive me more crazy. But thanks for every answer here, though I try that it still print out "I can do that" when the value of myvar is a float i.e 1.5, 2.5 and so on.
myaryat all. What does the array have to do with checking the value ofmyvar?myvar == nil? Or to put this the other way round: What is the actual problem you are trying to solve?