Menu Close

Comments & Block Comments – FORTRAN

Comments play a crucial role in code documentation and readability. They allow developers to add explanatory notes and remarks within their code without affecting the program’s execution.

Here, we will explore how to add comments and block comments in FORTRAN.

 

1. Comments in FORTRAN:

In FORTRAN, comments are lines of text that are ignored by the compiler during the compilation process.

They are used to provide information about the code, explain its purpose, or add any other relevant details.

In FORTRAN, comments begin with an exclamation mark (!)

Here’s an example of a single-line comment in FORTRAN:

! This is a comment in FORTRAN

In the above code snippet, the text following the exclamation mark is considered a comment and is ignored by the compiler.

 

2. Block Comments in FORTRAN

Unlike some other programming languages, FORTRAN does not have a built-in syntax for block comments, which are comments spanning multiple lines.

However, there are ways to achieve a similar effect by using single-line comments.

One common approach is to use a single-line comment for each line:

 

! This is a block comment in FORTRAN
! This comment spans
! multiple lines
! and provides additional
! information about the code.

 

More Related Stuff