[Gambas-user] Variable reinitialized at each iteration of a loop structure

BB adamnt42 at gmail.com
Tue Mar 28 01:15:15 CEST 2023


I think

In the first example

  dim a as integer = 1

is shorthand for

  dim a as integer
  a = 1

in the second example, try reading it like this:

for y = 0 to 2
for i = 1 to 1000000
dim b as integer <--- i.e. the "declaration" is implemented at the 
highest block.
      inc b
next
print "b=";b
next

You could try running it with the debug option to see this

b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230328/1c04661e/attachment.htm>


More information about the User mailing list