BEGIN
COMMENT THIS PROGRAM DEMONSTRATES THE FUNCTIONING OF THE 
        ALGOL-M ONENDFILE FEATURE USING TWO INPUT FILES;
% VARIABLE DECLARATIONS %

FILE FILE1,FILE2;
INTEGER A,I,J;
INTEGER ARRAY NUM[0:50];
STRING(5) FILEEND;
PROCEDURE ENDFILE(FILENUMBER);
   INTEGER FILENUMBER;
   BEGIN
     FILEEND:="TRUE";
     CASE FILENUMBER-1 OF 
       BEGIN
         WRITE("END OF FILE1 REACHED");
         WRITE("END OF FILE2 REACHED");
       END;
   END;

% PROGRAM EXECUTION BEGINS HERE %

% OPEN FILES %

FILE1:="FILE1.INP";
FILE2:="FILE2.INP";
I:=-1;
FILEEND:="FALSE";
WHILE FILEEND<>"TRUE" DO
  READ FILE1(NUM[(I:=I+1)]) ONENDFILE ENDFILE(1);
FILEEND:="FALSE";
I:=I-1;%RESET I%
WHILE FILEEND<>"TRUE" DO
  READ FILE2(NUM[(I:=I+1)]) ONENDFILE ENDFILE(2);
FOR J:=0 STEP 1 UNTIL I-1 DO
   WRITE(NUM[J]);
END
        
