| |
|
|
| 26 Jan 2015 02:52 PM |
Lots of ways. You can use the repeat function vvv
repeat [Code] until false (Looks at the wiki for more details)
You could also make a loop out of a function like vvv
function [Name]() [Code] [functionName]() end [functionName]()
(make sure to put a wait in the loop so you don't crash the game) |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 26 Jan 2015 02:53 PM |
@Pixel: 1) "repeat" isn't a function 2) Your recursion example would cause a stack overflow. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 26 Jan 2015 03:08 PM |
| As Droid said, it's better to run a loop instead of a recursion. Reason being that Lua needs memory from somewhere, and if you're filling up all the closures Lua is going to have a hard time. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 26 Jan 2015 03:09 PM |
| Lua does support tail call recursion, though I'm not sure how good at it it is. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 26 Jan 2015 03:10 PM |
| It's okay, but compared to stuff like C it's not too great. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 26 Jan 2015 03:14 PM |
In Haskell, all you can do is recursion. No loops. If you want to do something to each element in a list, use map:
map :: (a -> b) -> [a] -> [b] map _ [] = [] map f (x:xs) = f x : map f xs
double :: Num a => [a] -> [a] double = map (*2)
main = do putStrLn $ double [1..10] -- [2,4,6,8,10,12,14,16,18,20] |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 26 Jan 2015 03:15 PM |
| Yes but Haskell is functional, which isn't practical for games. |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 03:17 PM |
| Well sorry for giving him multiple answers to his question >.> |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 26 Jan 2015 03:17 PM |
| Not necessarily. It compiles to machine code so it is fast, it's just very different to write in. |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 03:20 PM |
Repeat . . . until 1 == 2
for i,0,math.huge . . . end -- for
but these are endless loops. What I imagine u mean is; "How do I stop a loop"?
use a condition
done = false
while not done do . if job_is_done then job = true; end -- job done? . end -- while
GL
|
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 03:33 PM |
function while(bool, func) if bool == true then return func() end end
while((x==5), function() print(x) end)
This is inefficient but it answers you question :D Then there's also the repeat/until keywords or the for/do loop. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 26 Jan 2015 03:35 PM |
| @War: That doesn't loop, just an if without an else, and you can't call a function "while". |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 03:48 PM |
| @Dr I know... You ruined my post D: |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 26 Jan 2015 03:51 PM |
o
while = (function()return(function(...)if(({...})[1])then return({...})[2]()end end))() |
|
|
| Report Abuse |
|
|