Skip to content

Commit

Permalink
Update variables.md (#382)
Browse files Browse the repository at this point in the history
Add local variables with block construct section
  • Loading branch information
jalvesz authored Feb 2, 2024
1 parent f7e795c commit 82ef0b8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions source/learn/quickstart/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,30 @@ end program float

In the next part we will learn how to use arrays for storing more than one
value in a variable.

## Local scope variables with `block` construct
The 2008 Fortran standard introduced the notion of `block` which enables using local scope variables within a program or procedure.

**Example:**

```{play-code-block} fortran
module your_module
implicit none
integer :: n = 2
end module
program main
implicit none
real :: x
block
use your_module, only: n ! you can import modules within blocks
real :: y ! local scope variable
y = 2.0
x = y ** n
print *, y
end block
! print *, y ! this is not allowed as y only exists during the block's scope
print *, x ! prints 4.00000000
end program
```

0 comments on commit 82ef0b8

Please sign in to comment.