Reputation: 123
Is it possible to have the start of a for-loop within an if-statement. For example:
if condition true
for j=1:10
else % condition false
for j=11:20
end % End of if-statement
% inner part of for-loop
end % End of for-loop
I know this is not the most beautiful approach, but in some cases it might be easier than simple coding.
Upvotes: 1
Views: 53
Reputation: 91017
No, that doesn't work.
But you can do
if condition
range=1:10
else % condition false
range=11:20
end % End of if-statement
for j=range
% inner part of for-loop
end % End of for-loop
Upvotes: 6