Fortran Cobol - sgml/signature GitHub Wiki
PROCEDURE DIVISION.
DECLARE-VARIABLES SECTION.
01 OPTION PIC X VALUE '1'.
Main-Process.
DISPLAY "Choose an option (1, 2, 3): ".
ACCEPT OPTION.
EVALUATE OPTION
WHEN '1' GO TO Option-One
WHEN '2' GO TO Option-Two
WHEN '3' GO TO Option-Three
WHEN OTHER GO TO Invalid-Option
END-EVALUATE.
Option-One.
DISPLAY "Option 1 Selected".
GO TO Main-Process.
Option-Two.
DISPLAY "Option 2 Selected".
GO TO Main-Process.
Option-Three.
DISPLAY "Option 3 Selected".
GO TO Main-Process.
Invalid-Option.
DISPLAY "Invalid Option".
GO TO Main-Process.
STOP RUN.
IDENTIFICATION DIVISION.
PROGRAM-ID. SpacebarLoop.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 KEY-CHAR PIC X.
01 CONTINUE-LOOP PIC X VALUE 'Y'.
PROCEDURE DIVISION.
Main-Loop.
DISPLAY "Press any key (press SPACE to stop): "
ACCEPT KEY-CHAR
IF KEY-CHAR = SPACE
MOVE 'N' TO CONTINUE-LOOP
ELSE
MOVE 'Y' TO CONTINUE-LOOP
END-IF
IF CONTINUE-LOOP = 'Y'
GO TO Main-Loop
END-IF.
STOP RUN.
IDENTIFICATION DIVISION. PROGRAM-ID. SpacebarLoop.
DATA DIVISION. WORKING-STORAGE SECTION. 01 KEY-CHAR PIC X. 01 CONTINUE-LOOP PIC X VALUE 'Y'.
PROCEDURE DIVISION. PERFORM UNTIL CONTINUE-LOOP = 'N' DISPLAY "Press any key (press SPACE to stop): " ACCEPT KEY-CHAR IF KEY-CHAR = SPACE MOVE 'N' TO CONTINUE-LOOP ELSE MOVE 'Y' TO CONTINUE-LOOP END-IF END-PERFORM. STOP RUN.
program validate_iso_date implicit none character(len=19) :: isoDate integer :: year, month, day, hour, minute, second logical :: isValid isoDate = '2023-12-31T23:59:59' read(isoDate(1:4), '(I4)') year read(isoDate(6:7), '(I2)') month read(isoDate(9:10), '(I2)') day read(isoDate(12:13), '(I2)') hour read(isoDate(15:16), '(I2)') minute read(isoDate(18:19), '(I2)') second isValid = .false. if (year >= 1000 .and. year <= 9999) then if (month >= 1 .and. month <= 12) then if (day >= 1 .and. day <= 31) then if (hour >= 0 .and. hour <= 23) then if (minute >= 0 .and. minute <= 59) then if (second >= 0 .and. second <= 59) then isValid = .true. endif endif endif endif endif endif if (isValid) then print *, 'Valid ISO 8601 date' else print *, 'Invalid ISO 8601 date' endif end program validate_iso_date