nested declarations



nested_declarations
Smart pascal source code
{ Special DWSII Syntax: It's possible to declare variables everywhere in the script code. The declaration is valid inside the active block and its sub-blocks. } var x: Integer; var s: Integer; for x := 0 to 10 do begin var s: string; // overrides previous declaration // of "s" (only inside this loop) s := IntToStr(x); WriteLn(s); end; for x := 0 to 10 do begin var s: Float; // overrides previous declaration // of "s" (only inside this loop) s := Sqrt(x); WriteLn(FloatToStr(s, 3)); end; for x := 0 to 10 do begin s := Round(Sqr(x)); // No redeclaration of "s" so // the initial declaration is used WriteLn(s); end; {<<< RESULT - CONSOLE LOG >>> ----------------------------- Errors >>>> Hint: Name "s" could be ambiguous in its scope context [line: 16, column: 7] Hint: Name "s" could be ambiguous in its scope context [line: 24, column: 7] Result >>>> 0 1 2 3 4 5 6 7 8 9 10 0.000 1.000 1.414 1.732 2.000 2.236 2.449 2.646 2.828 3.000 3.162 0 1 4 9 16 25 36 49 64 81 100 ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}