• Get all numbers between two numbers?
    5 replies, posted
Say I had number a, which was 30, and number b, which was 35. How would I get all the numbers between, so, a function that would return 30, 31, 32, 33, 34, 35 ? Thanks.
[lua] function GetBetween(Start,End) local Numbers = {} local WeAreAt = 0 for i=Start,End do Numbers[WeAreAt] = i WeAreAt++ end return Numbers end [/lua] Im learning lua so please post optimations
i did PrintTable( GetBetween( 30, 60 ) ) and it did this 1 = 31 2 = 32 3 = 33 4 = 34 5 = 35 6 = 36 7 = 37 8 = 38 9 = 39 10 = 40 11 = 41 12 = 42 13 = 43 14 = 44 15 = 45 16 = 46 17 = 47 18 = 48 19 = 49 20 = 50 21 = 51 22 = 52 23 = 53 24 = 54 25 = 55 26 = 56 27 = 57 28 = 58 29 = 59 30 = 60 0 = 30 wtf?
Good, it works Edit: Just as you know printtable print indexes in a wierd order :P
[QUOTE=hansihe;21672888][lua]WeAreAt++[/lua][/QUOTE] You can't do that in Lua [editline]08:03PM[/editline] [lua]function GetBetween(start, endn) local n = {} for i=start, endn do table.insert(n, i) end return n end[/lua]
*Scrambling that in my headluadatabase*
Sorry, you need to Log In to post a reply to this thread.