Two ping as a door counter

I monitor the values through the serial port and I notice when it changes from 7 but the problem as stated is when ping(1) changes the j-- isn't executed but when ping(2) changes j++ is executed
Thank you