strings and ranges

C

charlie.mills

The following program doesn't execute as I would expect:

#!/usr/bin/ruby

stringy = "X"

1.upto(10) do |i|
puts stringy
stringy.succ!
end

"X".upto("AG") do |ss|
puts ss
end

puts "'AB' > 'AA' = #{'AB' > 'AA'}"
puts "'X' < 'AA' = #{'X' < 'AB'}"

# The code below gets around my problem...

stringy = "X"
while true
puts stringy
stringy.succ!
break if stringy == "AH"
end

# Is there a better way?
# -Charlie
**************************************************************************************
This communication is intended solely for the addressee and is
confidential. If you are not the intended recipient, any disclosure,
copying, distribution or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. Unless indicated
to the contrary: it does not constitute professional advice or
opinions upon which reliance may be made by the addressee or any
other party, and it should be considered to be a work in progress.
**************************************************************************************
 
R

Robert Klemme

The following program doesn't execute as I would expect:

#!/usr/bin/ruby

stringy = "X"

1.upto(10) do |i|
puts stringy
stringy.succ!
end

"X".upto("AG") do |ss|
puts ss
end

puts "'AB' > 'AA' = #{'AB' > 'AA'}"
puts "'X' < 'AA' = #{'X' < 'AB'}"

# The code below gets around my problem...

stringy = "X"
while true
puts stringy
stringy.succ!
break if stringy == "AH"
end

# Is there a better way?

stringy = "X"
until stringy == "AH"
puts stringy
stringy.succ!
end

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,815
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top