Skip to content

Commit fcb2bf3

Browse files
committed
added error message when trying to alter a parameter
1 parent 900449f commit fcb2bf3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

episodes/02-basics.Rmd

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,28 @@ $ ./a.out
123123
2.00000000
124124
7.00000000
125125
```
126-
However, you can also define constant values that do not change by defining variables using `parameter`, e.g.
126+
However, you can also define constant values that cannot change by defining variables using `parameter`.
127+
We are then unable to modify `parameter` variables, e.g.
127128
```fortran
128129
program example3
129130
implicit none
130131
131132
real, parameter :: pi = 3.14159265
132133
134+
pi = pi + 2.0
135+
136+
print *, pi
137+
133138
end program example3
134139
```
140+
When compiling this program, this will give an error similar to the following from the `gfortran` compiler:
141+
```
142+
example3.f90:6:3:
143+
144+
6 | pi = pi + 2.0
145+
| 1
146+
Error: Named constant 'pi' in variable definition context (assignment) at (1)
147+
```
135148

136149
::::::::::::::::::::::::::::::::::::: challenge
137150

0 commit comments

Comments
 (0)