You set valid2
to false
, however valid
is still true. So your first while loop runs over and over again. The order of execution is as follows:
while(valid) == true
case 0:
get switchdata, set valid2 = true
second while loop
break
Repeat because valid is always true, switchtype never changes.