Give this a try

Code:
switch var PortB.0

main:
if switch = 1 then loop ' enter the loop
' do some thing here . . . 
goto main

loop:
if switch = 0 then main ' exit the loop
. . . loop code does something . . . 

goto loop