Hi, I’m going over some code, and I came across a function I’m having trouble understanding. Here it is, firstly:
local o = display.newGroup(); o.getStagedataByStageId = function(value) for i=1, #\_G.stages do if \_G.stages[i].stageId == value then return \_G.stages[i]; end end return \_G.stages[1]; end
I believe this function’s purpose is simply to return a value, but what I don’t understand is that there are two return statements. Because it’s read last, wouldn’t the one on the bottom override the previous return statement (the one in the if/then statement), making that statement redundant? In my head, I’m thinking (incorrectly of course) it should say something like:
if\_G.stages[i].stageId == value then return\_G.stages[i]; else return\_G.stages[1], end
I’m not an experienced coder, so I’m sure this question is very noobish. Can anyone help me understand?
Thanks in advance,
Steven