Variable declaration reset: Difference between revisions

Added PL/M
(Added Visual Basic .NET)
(Added PL/M)
Line 78:
Like the first/unchanged JavaScript example, under pwa/p2js there is no output (at least as things currently stand)<br>
Obviously you can achieve consistent results by manually hoisting the declaration of prev to before/outside the loop.
 
=={{header|PL/M}}==
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
Although PL/M has block scope, all variables are static, so PREV retains its value between iterations of the loop.<br>
Note the extra DO which is necessary to introduce a new scope as declarations are not allowed in a DO loop.
<lang pli>100H:
 
/* CP/M BDOS SYSTEM CALL */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5;END;
/* CONSOLE OUTPUT ROUTINES */
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$STRING( .( 0DH, 0AH, '$' ) ); END;
PR$NUMBER: PROCEDURE( N );
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR( 6 ) BYTE INITIAL( '.....$' ), W BYTE;
N$STR( W := LAST( N$STR ) - 1 ) = '0' + ( ( V := N ) MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
 
/* TASK */
DECLARE S( 6 ) BYTE INITIAL( 1, 2, 2, 3, 4, 4, 5 );
DECLARE I BYTE;
DO I = 0 TO LAST( S );
DO;
DECLARE ( CURR, PREV ) BYTE;
CURR = S( I );
IF I > 1 AND CURR = PREV THEN DO;
CALL PR$NUMBER( I );
CALL PR$NL;
END;
PREV = CURR;
END;
END;
 
EOF</lang>
{{out}}
<pre>
2
5
</pre>
 
=={{header|Visual Basic .NET}}==
3,043

edits