• How to actually use a for loop.
    4 replies, posted
Is it possible to have a for loop repeat a function until a certain condition is reached; for instance, foo = "hello"?
Use repeat / until or while (condition) do; the for loop is usually used for a fixed amount of iterations, unless you break out of it.
Actually, I think a [B]while[/B] loop is what you're looking for [lua] function funcName() --func stuff end while( condition ) do funcName() end [/lua] you've gotta think of it in reverse, though... like if you want to run "Hello World" into console 5 times, it would look something like this: [lua] local message = "Hello World" local runs = 0 function prntMsg() Msg( message ) runs = ( runs + 1 ) end while( runs < 5 ) do prntMsg() end [/lua]
That's what I said.
[lua] repeat i = i + 1 print(i) until foo == "hello" [/lua] Maybe this ?
Sorry, you need to Log In to post a reply to this thread.