7 decimal = %00000111

So, when Mister_e states:
Code:
sensor = sensor & 7 ' keep only sensor bits
The code does just what it says. It keeps only the values of the port bits GPIO 0,1, and 2.

and when Mister_e 's code:
Code:
until sensor != 7
This code checks GPIO to see if it is not = %00000111.