Loops
Loop variables should be initialized immediately before the loop
Loop variables should be initialized immediately before the loop
This improves loop speed and helps prevent bogus values if the loop does not execute for all possible indices.
result = zeros(nEntries,1);
for index = 1:nEntries
result(index) = foo(index);
end
The use of break and continue in loops should be minimized
The use of break and continue in loops should be minimized
These constructs can be compared to goto and they should only be used if they prove to have higher readability than their structured counterpart.
The end lines in nested loops can have comment
The end lines in nested loops can have comment
Adding comments at the end lines of long nested loops can help clarify which statements are in which loops and what tasks have been performed at these points.