a while loop ? Dunno if I understand the question correctly…
while [LOOP MATCHING CONDITION == TRUE] do
bleh
ATTENTION: Loop matching condition must change to false inside at some point, or while will loop forever. Or use a "break" statement.
end
Or a for loop, which is capable of increasing a counter by itself. for [START COUNT],[LOOP MATCHING CONDITION == TRUE],[COUNTER CHANGE] do
bleh
end
for [START COUNT],[COUNTER END VALUE],[COUNTER CHANGE] do
bleh
end
For assoziative arrays/object-containers (in LUA “tables”) you can use
for key IN table do
bleh
print(table[key])
end
Or if you want to have directly access to the value:
for key,value IN pairs(table) do
print(key,value)
end
function repeat_x4(song, a) --repeat 4 times with--> for do
song = renoise.song()
a = 4
for i = 1, a, 1 do
song:insert_track_at(song.selected_track_index)
end
end
Is there any way to do the same with " repeat" and " until"?
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.
I did not even know repeat statement, but looks for me like a workaround of lua, due lack of using do-while for this. In other languages:
do
bleh
while ([matching condition])
So in lua that thing with repeat. The diff to normal while is that it will process the inner code at least one time for sure.
In your case:
function my_personal_track_insert(num)
local song = renoise.song()
local i = 1
repeat
song:insert_track_at(song.selected_track_index)
i = i + 1
until i > num
end
...
my_personal_track_insert(4)
Or in combination with while:
function my_personal_track_insert(num)
local song = renoise.song()
local i = 1
repeat
song:insert_track_at(song.selected_track_index)
i = i + 1
while not (i > num) -- or while i <= num
end
...
my_personal_track_insert(4)
So basically, with until you define the condition when to stop, and with while the condition when to loop. Though it does not seem to make sense here to me to force one iteration. And I personally like the repeat-while variant much more, because it’s basically the same as a normal while.
Heh, maybe you should ask a lua geek in here instead, and I’ll shut up now. I also am a LUA hater.
function repeat_x4(song, a) --repeat 4 times with--> for do
song = renoise.song()
a = 4
for i = 1, a, 1 do
song:insert_track_at(song.selected_track_index)
end
end
Is there any way to do the same with " repeat" and " until"?
Errr…maybe?
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
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):
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?
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:
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
What warning do you mean?
With the current API version and with the current LUA version, with Renoise, it doesn’t matter which name precedes behind the “for”. It will not return any errors or any warnings. What is the problem here?