FOR loop counter is not updated if global

From Liberty BASIC Family
Revision as of 14:22, 14 September 2020 by StPendl (talk | contribs) (Text replacement - "Bug Tracker Categories" to "Bug Tracker")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Description

If a loop counter of a FOR loop is declared as global, it does not update inside the procedure the counter is used.

Example code to demonstrate the bug.

    global count

    count = 200

    print
    print "Counter befor procedure ... "; count

    call procedure

    print
    print "Counter after procedure ... "; count
    end

sub procedure
    print
    print "Counter at beginning of procedure ... "; count
    print

    for count = 1 to 10
        print "Counter inside loop ... "; count
    next

    print
    print "Counter at end of procedure ... "; count
end sub

Example code to work around the bug.

    global count

    count = 200

    print
    print "Counter befor procedure ... "; count

    call procedure

    print
    print "Counter after procedure ... "; count
    end

sub procedure
    print
    print "Counter at beginning of procedure ... "; count
    print

    for i = 1 to 10
        count = i
        print "Counter inside loop ... "; count
    next

    print
    print "Counter at end of procedure ... "; count
end sub