Variable declaration reset: Difference between revisions
Content added Content deleted
(Added Java) |
(→{{header|ALGOL 68}}: Better explanation and use UPB/LWB for more Algol 68-ness) |
||
Line 11: | Line 11: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
In Algol 68, things that aren't explicitely initialised are notionally initialised to SKIP - an indeterminate value, so there should be no output from the program. Each iteration of the loop will get a new curr and prev, with prev initialised to SKIP. The following is equivalent to the Phix program... |
|||
Algol 68 should produce no output as each iteration of the loop has a separate instance of the variables. |
|||
<br> |
|||
The Algol 68 equivalent of the Phix program is as below, whether this works as expected depends on how the implementation treats uninitialised variables... |
|||
<lang algol68>BEGIN |
<lang algol68>BEGIN |
||
[]INT s = ( 1, 2, 2, 3, 4, 4, 5 ); |
[]INT s = ( 1, 2, 2, 3, 4, 4, 5 ); |
||
FOR i |
FOR i FROM LWB s TO UPB s DO |
||
INT curr := s[ i ], prev; |
INT curr := s[ i ], prev; |
||
IF IF i > |
IF IF i > LWB s THEN curr = prev ELSE FALSE FI THEN |
||
print( ( i, newline ) ) |
print( ( i, newline ) ) |
||
FI; |
FI; |
||
Line 24: | Line 22: | ||
OD |
OD |
||
END</lang> |
END</lang> |
||
...however, one of the non-standard features of Algol 68G is that uninitialised variables cause a runtime error instead of silently being set to SKIP. |
|||
{{out}} with [[ALGOL_68_Genie|Algol 68G]]: |
{{out}} with [[ALGOL_68_Genie|Algol 68G]]: |
||
<pre> |
<pre> |
||
5 IF i > |
5 IF IF i > LWB s THEN curr = prev ELSE FALSE FI THEN |
||
1 |
1 |
||
a68g-2.8.3: runtime error: 1: attempt to use an uninitialised INT value (detected in |
a68g-2.8.3: runtime error: 1: attempt to use an uninitialised INT value (detected in BOOL conditional-clause starting at "IF" in this line).</pre> |
||
⚫ | |||
</pre> |
|||
⚫ | |||
No output. |
No output. |
||