Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2000-11-06
20:08 • Ticket [221240ffff] infinite loop - behaviour change from 8.0p2 status still... artifact: ba7f78f25a user: dkf
2000-11-04
00:43 • Ticket [221240ffff]: 4 changes artifact: 5ee17a6b50 user: tjamesjones
00:35 • Ticket [221240ffff]: 9 changes artifact: a49b48e06c user: welch
00:31 • Closed ticket [221240ffff]. artifact: 24de845096 user: dgp
2000-11-03
17:18 • New ticket [221240ffff]. artifact: ca6e0f12c7 user: tjamesjones

infinite loop - behaviour change from 8.0p2

Closed / Invalid221240ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-11-03 17:18:06
[ couldn't find this in the bug database.
 surprisingly, this "bug" is also in v8.0.5  so it
 has been around for a while]

we are trying to upgrade our version of Tcl from v8.0p2.
have discovered an odd behaviour for this Tcl code:

#
# START CODE
#

set foo 0

while $foo {
        puts "first loop"
}

set foo 1

while { $foo != 0 } {
        set foo 0
        puts "second loop"

}

set foo 1

while $foo {
        set foo 0
        puts "third loop"
}

#
# END CODE
#

you can run it from tclsh - the code gets stuck in an infinite loop on the third loop.
doesn't look right to me, yet I can't believe noone else has noticed this?   

this broke some of our code, as the behaviour under v8.0p2 was more as you'd expect, breaking out of the third loop after one iteration.

maybe Tcl has changed so that you can't say "while $var" although that doesn't really explain why it works for the first of the three loops.
dgpplain2000-11-04 00:31:36
1. This is not a bug.  The 8.0p2 behavior was buggy.

2. This has been reported before.  See Bug 118042 for
   a detailed response.

http://sourceforge.net/bugs/?group_id=10894&func=detailbug&bug_id=118042
welchplain2000-11-04 00:35:56
This is a behavior change, but the bug was in 8.0p2, not in other versions.  In
set foo 1
while $foo {
    set foo 0
}

the $foo is substituted *before* the while command is invoked, so the while
command doesn't see the variable reference.  (Or ought not to.  Early versions
of the byte-code compiler in 8.0 didn't correctly implement substitution semantics
in some control structures that have custom bytecodes generated for them.)
tjamesjonesplain2000-11-04 00:43:14
 excellent thankyou.  Now we can upgrade - and I was blaming poor old Tix all along.
dkf Ticket [221240ffff]: 3 changes [History diff]2000-11-06 20:08:07
Log in (anonymous is fine) to add a comment.