Use of iterator variables outside the for loop cc4m_logo_inline

IDFCNS-21
TitleDo not use iterator variables outside the for loop.
PriorityMandatory
Severity level2
DescriptionDo not use iterator variables outside the for loop, since this might lead to unexpected behavior.
RationaleUsing a loop iterator variable outside the for loop might indicate a programming error. For example if the for loop is not entered, the iterator variable becomes an empty double.

Avoid:

for iNode = 1 : numel(nodes)
    if valueIn(iNode) > threshold
		break;
	end
end

valueOut = iNode + 10;

Instead use:


idx      = 0;

for iNode = 1 : numel(nodes)
    ...
	
	if valueIn(iNode) > threshold
		idx      = iNode;
		break
	end
end

valueOut = idx + 10;