# Help with the ".times" command in ruby

**URL:** <https://www.ruby-forum.com/t/help-with-the-times-command-in-ruby/136235>\
**Category:** Ruby\
**Created:** [April 30, 2008, 12:47am UTC](https://www.ruby-forum.com/t/help-with-the-times-command-in-ruby/136235 "2008-04-30T00:47:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghysnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/db5fbb/32.png) [@ghysnon](https://www.ruby-forum.com/u/ghysnon)\
**Post date:** [April 30, 2008, 12:47am UTC](https://www.ruby-forum.com/t/help-with-the-times-command-in-ruby/136235/1 "2008-04-30T00:47:33Z")

</div>

Hey guys,

I’m trying to run a section of my ruby script 5000 times.  
Can someone show me how to do this, as I have no programming  
experience. Once I log into the BDI-3000 via Telnet, I just need  
to loop the section of the script from the date stamp line to the end  
of the script for 5000 times.

Here’s my script.

#!\ruby\bin\ruby.exe -w  
require ‘strscan’  
require ‘net/telnet’

$fileName = “Flash\_Loop”  
$outFile = File.new("…\\Temp\#{$fileName}.txt", “w”)

$outFile.puts “Flash loop to test the stability of flash chip after  
multiple flashes.”

$dut\_ip = “10.1.4.130”

Signal.trap(“INT”) do  
puts “Received INT killing #{$$}”

end

tn = Net::Telnet.new(“Host” =\> $dut\_ip, “Prompt” =\> /Core#0\>/) {|str|  
print str }

#######Date Stamp#########################################  
date\_result = IO.popen(“date /T”, “w+”)  
buffer = date\_result.readlines  
puts buffer  
$outFile.puts buffer  
date\_result.close  
time\_result = IO.popen(“time /T”, “w+”)  
buffer = time\_result.readlines  
puts buffer  
$outFile.puts buffer  
time\_result.close  
result = tn.cmd(“unlock 0x50000000 0x20000 3”) {|str| print str  
str  
}  
$outFile.puts result  
result = tn.cmd(“erase 0x50000000 0x20000 3”) {|str| print str  
str  
}  
$outFile.puts result  
result = tn.cmd(“prog 0x50000000 redboot64.bin BIN”) {|str| print str  
str  
}  
$outFile.puts result  
result = tn.cmd(“verify”) {|str| print str  
str  
}  
$outFile.puts result

$outFile.puts  
“---------------------------------------------------------------------”

---

<div class="post-metadata">

**Author:** ![ghysnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/db5fbb/32.png) [@ghysnon](https://www.ruby-forum.com/u/ghysnon)\
**Post date:** [April 30, 2008, 12:56am UTC](https://www.ruby-forum.com/t/help-with-the-times-command-in-ruby/136235/2 "2008-04-30T00:56:31Z")

</div>

You can use the times method like this:

5000.times do

# do some work

end

Regards,  
Craig

---

<div class="post-metadata">

**Author:** ![ghysnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/db5fbb/32.png) [@ghysnon](https://www.ruby-forum.com/u/ghysnon)\
**Post date:** [April 30, 2008, 1:27am UTC](https://www.ruby-forum.com/t/help-with-the-times-command-in-ruby/136235/3 "2008-04-30T01:27:51Z")

</div>

Craig D. wrote:

> You can use the times method like this:
> 
> 5000.times do
> 
> # do some work
> 
> end
> 
> Regards,  
> Craig

Thanks Craig,

I inserted your code and it works perfect.

-GHynson
