How switch between 2 different codes?

i am not sure how to do what your saying, I dont know what the conditional part of the loop is, i dont know how to set a global boolean variable,..