switch case character to for loop - if condition