switched for loop to while for control structures