Skip to content

Show how to declare multiple variables of the same type in one line #304

@Beliavsky

Description

@Beliavsky

The tutorial says

The syntax for declaring variables is:

<variable_type> :: <variable_name>
where <variable_type> is one of the built-in variable types listed above and <variable_name> is the name that you would like to call your variable.

In even the smallest programs one may have several variables of the same type, so I think it is worth introducing the syntax for this at the beginning. So the above could be changed to

The syntax for declaring variables is:

<variable_type> :: <variable_name_1>, <variable_name_2>
where <variable_type> is one of the built-in variable types listed above and <variable_name_1> and <variable_name_2> are the names that you would like to call your variables.

Then in the illustrative program

program arithmetic
  implicit none

  real :: pi
  real :: radius
  real :: height
  real :: area
  real :: volume

the declarations can be consolidated to one line. Modern Fortran has been criticized as verbose -- I think concise syntax should be used when it does not sacrifice clarity.

A nitpick about the code is that the line

area = pi * radius**2.0

should be

area = pi * radius**2

When you want to raise a value to an exact integer power, you should not write the exponent as a float.

Typo -- "running" not "runnning" (2 not 3 n's) at https://fortran-lang.org/learn/quickstart/arrays_strings .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions