How to jump to first loop if nest for loop need to terminate due to condition

6 views (last 30 days)
I am using nested for loops as below, (i) is number of files read and (j) is tline=fgetl(fid). when tline return -1 fprintf give error. when tline in j loop return -1 I want to jump to i loop to read next file and overpass the error in j loop.
for i=1:10
for j=1:100
%code
tline=fgetl(fid)
fprintf(fid,tline)
end
end

Accepted Answer

David Hill
David Hill on 17 Aug 2022
for i=1:10
for j=1:100
%code
tline=fgetl(fid)
if tline==-1
break;
end
fprintf(fid,tline)
end
end

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!