#2293·pry

Last iteration of loop is incomplete

Author: rabdelazimCreated Nov 2, 2023Updated Nov 6, 2023

I noticed a strange behavior the other day. I'm looping through some JSON to print out certain elements but for some reason, PRY does not print the last line of the JSON file. The only thing that seemed to get the print statement to work was to specify it twice. So here is my code for example:

1         def chart(depth=0)
2            print self.name 
3             self.behaviors.each do |b|
4                print  "\n" + "  "*(depth+1) + "|" + b['name']
5             end
6             depth += 1
7            
8             for child in self.children 
9                 print "\n" + "  "*depth + "+--"
10                child.chart(depth)
11            end
12        end

What happens in PRY is that the last set of behaviors (lines 3-5) does not execute. If I were to repeat the same loop a second time, the behaviors all show up twice as expected. This isn't an issue with my code because when I run the code outside of PRY, there are no missing elements.