From fcb2bf3a281c64a79825d584023154eacf0340e2 Mon Sep 17 00:00:00 2001 From: Luke Abraham Date: Mon, 2 Dec 2024 16:19:58 +0000 Subject: [PATCH] added error message when trying to alter a parameter --- episodes/02-basics.Rmd | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/episodes/02-basics.Rmd b/episodes/02-basics.Rmd index b61667c..46bbdab 100644 --- a/episodes/02-basics.Rmd +++ b/episodes/02-basics.Rmd @@ -123,15 +123,28 @@ $ ./a.out 2.00000000 7.00000000 ``` -However, you can also define constant values that do not change by defining variables using `parameter`, e.g. +However, you can also define constant values that cannot change by defining variables using `parameter`. +We are then unable to modify `parameter` variables, e.g. ```fortran program example3 implicit none real, parameter :: pi = 3.14159265 + pi = pi + 2.0 + + print *, pi + end program example3 ``` +When compiling this program, this will give an error similar to the following from the `gfortran` compiler: +``` +example3.f90:6:3: + + 6 | pi = pi + 2.0 + | 1 +Error: Named constant 'pi' in variable definition context (assignment) at (1) +``` ::::::::::::::::::::::::::::::::::::: challenge