MATLAB: While 1 and fget1 loop.

while loop

fide = fopen('data.13o')
head_lines = 0
while 1
head_lines = head_lines+1
line = fgetl(fide)
answer = findstr(line,'END OF HEADER')
if ~isempty(answer), break; end
end
% the header of the data.13o file is;
OBSERVATION DATA M RINEX VERSION / TYPE
LEICA GEO OFFICE 5.0 10-5-13 10:45 PGM / RUN BY / DATE
OBSERVER / AGENCY
O2930689 MARKER NAME
O2930689 MARKER NUMBER
P8UO0W21QTC -Unknown- -Unknown- REC # / TYPE / VERS
-Unknown- TPSGR3 NONE ANT # / TYPE
4303634.7047 2746069.9471 3812585.4149 APPROX POSITION XYZ
1.3289 0.0000 0.0000 ANTENNA: DELTA H/E/N
L1PhaOff: 0.2338 L2PhaOff: 0.2252 COMMENT
1 1 WAVELENGTH FACT L1/2
7 C1 P1 L1 D1 P2 L2 D2 # / TYPES OF OBSERV
2013 4 13 4 56 30.000000 TIME OF FIRST OBS
2013 4 13 7 59 0.000000 TIME OF LAST OBS
16 LEAP SECONDS
27 # OF SATELLITES
END OF HEADER
%this loop works what it supposed to be but I couldn't understand how "while 1" works for this loop and what's the difference between "while 1" and while for the loop.

Best Answer

while 1 is the same as while true. It means loop forever. The only way to stop the loop is to use a break statement, which is what you're doing with the
if ~isempty(answer), break; end
Another way to write the loop would have been:
answer = '~'; %anything not empty so the loop starts
while ~isempty(answer)
head_lines = head_lines+1
line = fgetl(fide)
answer = findstr(line,'END OF HEADER')
end