I have a project with a few relays and a 12 volt dc motor. The motor opens and closes a door based on a light and dark (LDR) The door has hall sensors to limit travel. For the most part everything works fine but every so often the door starts to open and then the program goes into a loop or crashes. I compiled the program with the watchdog timer off. Since this start happening I did some research and found that without the watchdog timer employed the program can be reset after a per-determined time period. Obviously, I need to turn watchdog on. However, I have a question about my code that may be contributing to the problem.

Below is a sample of a "DO Loop" I use:

If (Light = 1) and (DoorClosed = 0) then

Relay2 = 1
DO
Loop until DoorOpen = 0
Relay2 = 0

End if

Notice there is no statement after "DO". It goes immediately to the "loop until DoorOpen = 0." This does work but I'm wondering if this might be contributing to the problem. Is this a proper way of using the DO Loop? That is without a statement in between DO and Loop?