HI, the code that I wrote is to make the PORTB count from 0 to 255, and after that, to make the PORTA count from 0 to 31, and back to incrementing PORTB 255 and so on. but it didn't work that way while i'm simulating it on mplab, after incrementing portb to 255, and PORTA TO 31, it continued incrementing porta from 0-31-0-31... and never escaped the loop. Can someone please try to simulate it on their mplab and see for them selves what's happening, and maybe give a possible explanation
RA4 is an open collector output, so it can't go high unless you have a pullup resistor - so as soon as your count reaches RA4 it's reset to zero (as RA4 can't go high).
Because it's not going to zero on the WRITE, but on the READ instead, so it READS zero back from the port, increments it, then WRITES it back - THEN it checks for zero (which it never will be, as it can never reach 255).
No problem! - one point though, it's not considered good practice to directly increment the ports (I think you perhaps now know why?), you should increment a GPR (General Purpose Register) and then move it to the port. If you'd done it that way, your program would have worked.