In your wording, “current” is a variable, but it has nothing assigned to
it so it is nil.
If you want to show the current value of “i”, then just write “puts i”.
If you want to gather each line for some sort of comparison I’d
personally read each into an array with something like “my_array.push”
and then compare two arrays afterwards.
you cannot change “living” Ruby code like you try to do. That is, you
cannot just inject a #{i} somewhere and have the Ruby interpreter
process it as if the value was actually in the code.
If you want to dynamically create variables, you either need
metaprogramming or eval() with the latter always being the last resort
(“eval() is evil”). For local variables, however, eval() is really the
only
possibility – which already shows there’s something wrong.
If you want to collect values, use arrays like Joel suggested. Don’t use
variables with an index appended to them. That’s extremely ugly to work
with and just unclean.
You should also note that “while” loops and manual counter arithmetic is
rather rare in Ruby. Unlike BASIC or C or something, Ruby is a high
level language that relies on more intelligent methods like “upto” or
“each” or “each_with_index”. You rarely ever have to do this “i += 1”
stuff.
this is currently is going to out of my knowledge …
thanks for help
Ever heard of if-statements?
Also:
your while loop is very un-idiomatic
do not use global variables
the indentation is a mess
you have an `end’ too much, which should cause an infinite loop
As I told you already months ago, you finally should start to learn
the basics (now). You also should not ignore the advice you get here,
but instead try to use it to improve your programming skills.
Hi Thanks …
That extra end was copy past mistakes.
I Tryed to use if else but the logic is not entering
In my head.
How to compare 3 values …
I was thinking to do sorting then some how comparing
But because of 3 values I’m confused.
Thanks for further advice.