What you are thinking is totally wrong.
If
is not a loop its a conditional statement
what you want here is a for
loop
for n = 1:size(locs)
% your code
end
also times
take two parameter and you should figure it out yourself what it should be