break void function when the condition is met

thanks in advance.
But for me the problem is not in the code formatting ,the problem when the counter=2 the 2nd led turns on while the 1st one still working . i just need the first led turns off once the 2nd led turns on( counter=2)
hope you understand me ;(..