Each code-wrap is a train track.
The bot will only "ride the rails" if it meets the requirements.  
Track 1:  If the player is in the dungeon.
Track 2:  If the player is not in the dungeon.
Track 3:  If the player is in Stormwind. - etc
Track 4:  Detection Diamond
Track 5:  Dungeon codes.
Track 1 will always be checked first when the profile starts, if the bot meets those requirements - it will execute it.  And it won't stop executing it until it's complete.
After it's complete, track 2 - 3 ----->
Like I was saying with the death code.  It would be Track 6.  But in order to start Track 6, Track 5 would need to be stopped, which that's the tricky part.
So yea, we can put a "If in dungeon, leave." code at the beginning of the profile.  No problem.
I think making it navigate out of the dungeon would be better for a global solution considering some people have Hearths that go across the world.
I'll put instructions in the code so you can choose between Hearth/Navigate.