kirda

3

Mar 6th, 2021
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.59 KB | None | 0 0
  1. local function multiply_list_with_number(list, int, new_int)
  2.     for index in ipairs(list) do
  3.         list[index] = list[index] * int + new_int
  4.     end
  5. end
  6.  
  7. local list = {0, 2, 4, 5}
  8.  
  9. multiply_list_with_number(list, 2, 5)
  10.  
  11. print(list) >> {5, 9, 13, 15}
  12.  
  13. -- ipairs works similar to pairs, however it has some differences
  14. -- 1. it breaks the loop when value it loops through is nil
  15. -- 2. it loops in order so if your array looks similar to this
  16.     list = {}
  17.     list[1] = 25
  18.     list[3] = 50
  19.     -- the ipairs loop will break after the first index because
  20.     -- list[2] is not assigned to anything, it's nil
Advertisement
Add Comment
Please, Sign In to add comment