# \[Solved\] Help: repeat a function "x" times

**URL:** <https://forum.renoise.com/t/solved-help-repeat-a-function-x-times/47060>\
**Category:** Renoise Tool Development\
**Created:** [December 10, 2016, 2:22pm UTC](https://forum.renoise.com/t/solved-help-repeat-a-function-x-times/47060 "2016-12-10T14:22:32Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Raul](https://forum.renoise.com/user_avatar/forum.renoise.com/raul/32/2484_2.png) [@Raul](https://forum.renoise.com/u/Raul)\
**Post date:** [December 10, 2016, 3:46pm UTC](https://forum.renoise.com/t/solved-help-repeat-a-function-x-times/47060/6 "2016-12-10T15:46:43Z")

</div>

> Hm, sorry. I think I mixed up things (again), cause lua-for-loops are different to other languages, kinda special :X. Will correct† above.
> 
> Yes looks right to me. But don’t know for sure without testing.

Thanks **ffx** for the help! 🙂

I am simply looking for a simple function to repeat, with **repeat** and **until**. For example (with os.clock):

```auto
local starttime = os.clock()
print("I'm about to spam you horribly for 1.5 seconds")
repeat
	print("SPAM!")
until os.clock() - starttime > 1.5
print("All done :P")

```

Very interesant! Repeat a function 1.5 seconds.Instead, I want to repeat only 5 times

Possibly **repeat** and **until** does not work, and I must use **for** and **do**.

> Errr…maybe?
> 
> ```auto
> function repeat_x4(song, a) --repeat 4 times with--> repeat until
> song = renoise.song()
> a = 1
> repeat
> song:insert_track_at(song.selected_track_index)
> a = a + 1
> until a > 4
> end
> 
> ```

jajajaImpressed with speed!!! Perfect and solved!!! Taaaaaaanks **4Tey**!!!

The functions:

```auto
function amic_CH04_5B(song, a) --repeat x4 with "repeat until"
  song = renoise.song()
  a = 1
  repeat
    song:insert_track_at(song.selected_track_index)
    a = a + 1
  until a > 4
end

function amic_CH04_6B(song, a) --repeat x4 with "for do"
  song = renoise.song()
  a = 4
  for i = 1, a, 1 do
    song:insert_track_at(song.selected_track_index)
  end
end

function amic_CH04_6B(song, a) --repeat x4 with "for do"
  song = renoise.song()
  a = 4
  for i = 1, a do
    song:insert_track_at(song.selected_track_index)
  end
end

```

Any idea with vertical scrollbar ? :[https://forum.renoise.com/t/solved-help-create-an-area-with-vertical-scrollbar-with-buttons-in/47059](https://forum.renoise.com/t/solved-help-create-an-area-with-vertical-scrollbar-with-buttons-in/47059)

---

_[View the full topic](https://forum.renoise.com/t/solved-help-repeat-a-function-x-times/47060)._
