i = 0 j = 0 loop = 0 cnt = {555,5,222,232,775,23,110,343,12,543,353,3,45,24,88,32,453,75} --original array local inst = mc.mcGetInstance(); function bubbleSort(Hz) -- to show how a sort is done local itemCount = #Hz --use a "#" symbol to get the count local hasChanged local k = 0 repeat hasChanged = false itemCount = itemCount - 1 for k = 1, itemCount do if Hz[k] > Hz[k + 1] then Hz[k], Hz[k + 1] = Hz[k + 1], Hz[k] hasChanged = true end end until hasChanged == false end function CallMe(loop) i=i+1 local counts = tonumber(cnt[i]) if (loop >= #cnt) then return end if (counts < 100) then mc.mcCntlSetLastError(inst, "Loop number, low value: ".. cnt[i]); elseif (counts > 99 and counts < 400) then mc.mcCntlSetLastError(inst, "Loop number, mid value: ".. cnt[i]); else mc.mcCntlSetLastError(inst, "Loop number, high value: ".. cnt[i]); end CallMe(loop+1) --iterative function. i = 0 --reset it you might need it again return end function Sorted(loop) loop=loop+1 local counts = tonumber(cnt[loop]) if (loop >= #cnt+1) then return end --mc.mcCntlSetLastError(inst, "Loop number, low to high sorted: ".. tostring(counts)); Sorted(loop) --iterative function. return end function main() CallMe(0) bubbleSort(cnt) --Sorted(0) --[[ for i = 1, #cnt do mc.mcCntlSetLastError(inst, "cnt array now sorted: ".. cnt[i]); end ]] CallMe(0) end if (mc.mcInEditor() == 1) then main() else main() end