removed this part to ask if this loop will function as described.
You need a state machine for doing this type of things
You could approach that quite easily with a bunch of booleans, one for each possible state.
Basically you need to sit in some kind of idle state, poling the sensors. If you get a trigger from sensor 2 or 3 at idle, ignore them. If you get a hit from sensor 1, you go to state say 1A. In 1A, the only valid hit is sensor 2, which takes you to 2A. In 2A only a 3 is valid, to go to 3A; from there only a hit on sensor 4 is valid taking you to state 4A, a valid end state.
If at idle you get a hit from sensor 4, you go to state 4B, from which a hit on sensor 3 is the only escape… etc etc.
You need to differentiate between the 2 ways to get a hit on sensor 4: 4A means you got to an end via 1-2-3-4 and 4B means you’re starting a downward trip from idle.
If you ever get to 4A that means you completed the path going up, and if you ever get to 1B you went down.
Valid paths are thus:
edit: and presumably once you did whatever you were supposed to do when you got to an end state, you would go back to idle for next time. I would probably rename the states to indicate direction, rather than A and B
Doing this with booleans and ifs is a simple way. There are other ways of course, and in this thread PaulMurrayCbr shows how you could do that with classes and objects: probably not too n00b friendly though.