From: Bob Gustafson Date: 2001-09-28T07:30:03+09:00 Subject: [ruby-talk:21789] single line loop oddity I am trying to debug a program with a loop which contains one executable line (see below) [user1@hoho0 cron]$ cat loop-prob.rb tub = ["First phrase","Second phrase"] tub.each do |line| puts line # puts line.reverse end puts "*** Done with LOOP **" When I run the program with the debugger, when I execute the one line (puts line) inside the loop, instead of going just once around the loop (and printing one line), it does not stop, but continues to the end of the loop without stopping. This is annoying - particularly when the loop goes around many times. (I don't know if the program is wrong, or the debugger is wrong) Note that the variable 'line' is printed with the debugger command p before the s which goes to the end of the loop. It contains just the first phrase. [user1@hoho0 cron]$ ruby -r debug loop-prob.rb Debug.rb Emacs support available. loop-prob.rb:1:tub = ["First phrase","Second phrase"] (rdb:1) s loop-prob.rb:2: tub.each do |line| (rdb:1) s loop-prob.rb:3: puts line (rdb:1) p line "First phrase" (rdb:1) s First phrase Second phrase loop-prob.rb:6: puts "*** Done with LOOP **" (rdb:1) s *** Done with LOOP ** [user1@hoho0 cron]$ ----- If I take the comment # out of the program, so that there are two statements within the loop, then the debugger behaves correctly (executing only one line for each debugger 's' command - see transcript below). [user1@hoho0 cron]$ ruby -r debug loop-prob.rb Debug.rb Emacs support available. loop-prob.rb:1:tub = ["First phrase","Second phrase"] (rdb:1) n loop-prob.rb:2: tub.each do |line| (rdb:1) s loop-prob.rb:3: puts line (rdb:1) s First phrase loop-prob.rb:4: puts line.reverse (rdb:1) s esarhp tsriF loop-prob.rb:3: puts line (rdb:1) s Second phrase loop-prob.rb:4: puts line.reverse (rdb:1) s esarhp dnoceS loop-prob.rb:6: puts "*** Done with LOOP **" (rdb:1) s *** Done with LOOP ** [user1@hoho0 cron]$ There seems to be a problem in the interaction between the debugger and program loops containing one line.