Rework for loops to use iterators, requiring pairs or ipairs function to handle multi-assignment

This commit is contained in:
2018-11-24 14:35:23 +01:00
parent c63df3c941
commit 13ac6f2754
10 changed files with 132 additions and 16 deletions

View File

@@ -85,7 +85,7 @@ return a
const string input = @"
arr = {100, 56, 28}
value = 0
for key, val in arr do
for key, val in ipairs(arr) do
value = value + val
end
return value
@@ -103,7 +103,7 @@ return value
const string input = @"
arr = {100, 56, 28}
value = 0
for key, val in arr do
for key, val in ipairs(arr) do
local keyInt = tonumber(key)
value = value + keyInt
end

View File

@@ -206,7 +206,7 @@ end
const string input = @"
arr = {100, 56, 28}
value = 0
for key, val in arr do
for key, val in ipairs(arr) do
value = value + tonumber(key)
end
return value

View File

@@ -51,7 +51,7 @@ b = a
const string input = @"
arr = {100, 56, 28}
local value = 0
for key, val in arr do
for key, val in ipairs(arr) do
value = value + val
end
return value