# Choosing which connection to travel down efficiently

Suppose i want to check if my position is enclosed in a closed loop by following the connection of waypoints that surround it:

Now if i travel from node 0 to node 1. I'm at node 1 and i need to find the next connection of which as you can see i have multiple choices this time.

I can rule out where i came from quite easily, but that still leaves me with other options. How can I optimally pick which connection to follow next based on knowing that the connection from node 1 to node 2 is the only allowed option here anyway since as it's an enclosed loop you can consider them equivalent to being walls. I just am not sure how to check which is the most viable choice next logically speaking.

If node 1 to node 2 connection didn't exist, naturally the first logical choice would be to just go straight on ahead which is easy to tell visually just not so easy when thinking in code.

Roughly speaking, you don't need to check anything, you just pick any unused edge from the current node $$v$$, and sooner or later you will be forced to come back to $$v$$. However, this might leave out some edges of the network, so in case you want to cover them all, you have to start a new circuit from a node that you already reached and "paste it in" your old circuit.