Variable declaration reset: Difference between revisions
→{{header|ALGOL 68}}: Better explanation and use UPB/LWB for more Algol 68-ness
(Added Java) |
(→{{header|ALGOL 68}}: Better explanation and use UPB/LWB for more Algol 68-ness) |
||
Line 11:
=={{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...
<lang algol68>BEGIN
[]INT s = ( 1, 2, 2, 3, 4, 4, 5 );
FOR i
INT curr := s[ i ], prev;
IF IF i >
print( ( i, newline ) )
FI;
Line 24 ⟶ 22:
OD
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]]:
<pre>
5 IF IF i >
1
a68g-2.8.3: runtime error: 1: attempt to use an uninitialised INT value (detected in
...whereas, with [[Rutgers_ALGOL_68|Rutgers Algol 68]]:<br>▼
▲with [[Rutgers_ALGOL_68|Rutgers Algol 68]]:<br>
No output.
|