[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Counting Program

Dan Diebolt

4/21/2008 3:14:00 AM

[Note: parts of this message were removed to make it a legal post.]

>it's as simple as ...

adding an argument list:

10.times do |time1|
puts time1+1
end

11 Answers

Will Mueller

4/25/2008 11:53:00 AM

0

If I was to revise it to be able to simply type in a number and then
allow the program to count up to that on the screen how should it be
revised?

time2=(something with user input)
puts time2+=1
end

Something like that?

On Wed, Apr 23, 2008 at 2:15 PM, Dana Merrick <dana.merrick@trincoll.edu> wrote:
> Or even use a range:
>
> (1..10).each { |num| p num }
>
>
>
> Dan Diebolt wrote:
>
> >
> > > it's as simple as ...
> > >
> >
> > adding an argument list:
> >
> > 10.times do |time1|
> > puts time1+1
> > end
> >
> >
>
>



--
Will M
wce.page.tl
freetechtips.tk
will.liljon@gmail.com

David A. Black

4/25/2008 12:04:00 PM

0

Hi --

On Thu, 24 Apr 2008, Dana Merrick wrote:

> Dan Diebolt wrote:
>>> it's as simple as ...
>>
>> adding an argument list:
>>
>> 10.times do |time1|
>> puts time1+1
>> end
>>
>
> Or even use a range:
>
> (1..10).each { |num| p num }

If you really just want to print out the numbers:

puts *1..10


David

--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
INTRO TO RAILS June 24-27 London (Skills Matter)
See http://www.r... for details and updates!

Will Mueller

4/25/2008 8:08:00 PM

0

No, I mean in a manner that allows user input. So you may type in a
number then allow the computer to count to that number.

On Fri, Apr 25, 2008 at 7:03 AM, David A. Black <dblack@rubypal.com> wrote:
> Hi --
>
>
> On Thu, 24 Apr 2008, Dana Merrick wrote:
>
>
> > Dan Diebolt wrote:
> >
> > >
> > > > it's as simple as ...
> > > >
> > >
> > > adding an argument list:
> > >
> > > 10.times do |time1|
> > > puts time1+1
> > > end
> > >
> > >
> >
> > Or even use a range:
> >
> > (1..10).each { |num| p num }
> >
>
> If you really just want to print out the numbers:
>
> puts *1..10
>
>
> David
>
> --
> Rails training from David A. Black and Ruby Power and Light:
> INTRO TO RAILS June 9-12 Berlin
> ADVANCING WITH RAILS June 16-19 Berlin
> INTRO TO RAILS June 24-27 London (Skills Matter)
> See http://www.r... for details and updates!
>
>



--
Will M
wce.page.tl
freetechtips.tk
will.liljon@gmail.com

John

4/25/2008 8:16:00 PM

0

On Apr 25, 10:08 am, Will Mueller <will.lil...@gmail.com> wrote:
> No, I mean in a manner that allows user input. So you may type in a
> number then allow the computer to count to that number.
>

require 'readline'

num = ask('Count to what number?: )

num.times do |x|
puts x
sleep 1
x += 1
end

end

John

4/25/2008 8:18:00 PM

0

edit:

> require 'highline'
>
> num = ask('Count to what number?: )
>
> num.times do |x|
> puts x
> sleep 1
> x += 1
> end
>
> end

John

4/25/2008 8:30:00 PM

0

Moral of the story: run your code before they all laugh at you.

require 'rubygems'
require 'highline/import'


count = ask('Count to what number?: ')

c = 0

amt = count.to_i + 1

amt.times do |c|
puts c
c += 1
sleep 1
end

Will Mueller

4/25/2008 9:47:00 PM

0

Received the following error: realcountin.rb:3 unterminated string
meets end of file

realcounting.rb:3: syntax error, unexpected $end, expecting ')'

On Fri, Apr 25, 2008 at 3:20 PM, John <john.d.perkins@gmail.com> wrote:
> On Apr 25, 10:08 am, Will Mueller <will.lil...@gmail.com> wrote:
> > No, I mean in a manner that allows user input. So you may type in a
> > number then allow the computer to count to that number.
> >
>
> require 'readline'
>
> num = ask('Count to what number?: )
>
> num.times do |x|
> puts x
> sleep 1
> x += 1
> end
>
> end
>
>



--
Will M
wce.page.tl
freetechtips.tk
will.liljon@gmail.com

Will Mueller

4/25/2008 9:49:00 PM

0

Still getting an error after editing to make:

require 'rubygems'
require 'highline/import'


count = ask('Count to what number?: ')

c = 0

amt = count.to_i + 1

amt.times do |c|
puts c
c += 1
sleep 1
end

Much larger error.



On Fri, Apr 25, 2008 at 4:47 PM, Will Mueller <will.liljon@gmail.com> wrote:
> Received the following error: realcountin.rb:3 unterminated string
> meets end of file
>
> realcounting.rb:3: syntax error, unexpected $end, expecting ')'
>
>
>
> On Fri, Apr 25, 2008 at 3:20 PM, John <john.d.perkins@gmail.com> wrote:
> > On Apr 25, 10:08 am, Will Mueller <will.lil...@gmail.com> wrote:
> > > No, I mean in a manner that allows user input. So you may type in a
> > > number then allow the computer to count to that number.
> > >
> >
> > require 'readline'
> >
> > num = ask('Count to what number?: )
> >
> > num.times do |x|
> > puts x
> > sleep 1
> > x += 1
> > end
> >
> > end
> >
> >
>
>
>
>
>
> --
> Will M
> wce.page.tl
> freetechtips.tk
> will.liljon@gmail.com
>



--
Will M
wce.page.tl
freetechtips.tk
will.liljon@gmail.com

Peter Bunyan

4/25/2008 10:30:00 PM

0

print "Upto what number? " # ask the question
max = gets.to_i # get a string and convert it to a number
puts *(1..max) # creates a range from 1 to max, then turns it into an
array, then prints each one.
--
Posted via http://www.ruby-....

John

4/25/2008 10:31:00 PM

0

How are you running this? My snippet works from the command line, I
don't know about irb. Save it as 'countly.rb' and try >ruby countly.rb

Interesting.