Menu Close

Executable and Non Executable Statement – FORTRAN

In Fortran, code statements are divided into two main categories: executable statements and non-executable statements.

1. Executable statements:

These statements perform computations or control the flow of the program. They are executed in a sequential order, one after another.

Some examples of executable statements in Fortran include assignment statements, arithmetic operations, loops (DO, IF-THEN, etc.), and subroutine/function calls.

These statements are typically used to carry out calculations and perform actions.

 

Example

program AbsoluteValueExample
program ExecutableExample
  implicit none

  integer :: x, y, z

  x = 10
  y = 5
  z = x + y

  write(*,*) "The sum of x and y is:", z

end program ExecutableExample

In this example, the assignment statement (z = x + y) and the write statement (write(*,*)) are executable statements, because they perform computations and control the output of the program.

 

2. Non-executable statements

These statements provide additional information to the compiler or perform tasks that are not executed during the runtime of the program, for example – comments.

They are used for declaring variables, specifying program options, defining functions/subroutines, and including external files.

Non-executable statements are typically used for program organization and defining program structure. 

Example

program NonExecutableExample
  implicit none

  ! This is a comment, which is a non-executable statement
  integer :: x, y, z  ! Variable declarations

end program NonExecutableExample

 

In this example, the comment (! This is a comment) and the variable declarations (integer :: x, y, z) are non-executable statements.

They provide information to the compiler and help in organizing the code but do not perform computations or control the program flow during runtime.

More Related Stuff