How can I run a command five times using Ruby?
To run a command 5 times in a row, you can do
5.times { send_sms_to("xxx") }
For more info, see the times
documentation and there's also the times
section of Ruby Essentials
You can use the times
method of the class Integer
:
5.times do
send_sms_to('xxx')
end
or a for
loop
for i in 1..5 do
send_sms_to('xxx')
end
or even a upto
/downto
:
1.upto(5) { send_sms_to('xxx') }