FOR loop counter is not updated if global

From Liberty BASIC Family
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