| 1 | program test_syntax |
| 2 | ! Test program for syntax highlighting |
| 3 | use iso_fortran_env, only: int32, real64 |
| 4 | implicit none |
| 5 | |
| 6 | integer :: i, n = 10 |
| 7 | real(real64) :: pi = 3.14159265359 |
| 8 | character(len=20) :: greeting = "Hello, Fortran!" |
| 9 | |
| 10 | ! Print greeting |
| 11 | print *, greeting |
| 12 | |
| 13 | ! Calculate factorial |
| 14 | print *, "Factorial of", n, "is", factorial(n) |
| 15 | |
| 16 | ! Loop example |
| 17 | do i = 1, 5 |
| 18 | if (mod(i, 2) == 0) then |
| 19 | print *, i, "is even" |
| 20 | else |
| 21 | print *, i, "is odd" |
| 22 | end if |
| 23 | end do |
| 24 | |
| 25 | contains |
| 26 | |
| 27 | recursive function factorial(n) result(fact) |
| 28 | integer, intent(in) :: n |
| 29 | integer :: fact |
| 30 | |
| 31 | if (n <= 1) then |
| 32 | fact = 1 |
| 33 | else |
| 34 | fact = n * factorial(n - 1) |
| 35 | end if |
| 36 | end function factorial |
| 37 | |
| 38 | end program test_syntax |