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