
-----------------------------------
kris
Sun May 30, 2004 12:20 am

convert switch case to if else
-----------------------------------
can any1 help me to change this code to if-else statements...

     char ch = input.charAt(j); 

 switch(ch)
            {
            case '+':               // it's + or -
            case '-':
               gotOper(ch, 1);      // go pop operators
               break;               //   (precedence 1)
            case '*':               // it's * or /
            case '/':
               gotOper(ch, 2);      // go pop operators
               break;              //   (precedence 2)
            case '(':               // it's a left paren
               theStack.push(ch);   // push it
               break;
            case ')':               // it's a right paren
               gotParen(ch);        // go pop operators
               break;
            default:                // must be an operand
               output = output + ch; // write it to output
               break;

-----------------------------------
Dan
Sun May 30, 2004 12:48 am


-----------------------------------

if(ch == '+' || ch == '-')
{
          gotOper(ch, 1);
}
else if(ch == '*' || ch == '/')
{
           gotOper(ch, 2);
}
//and so on with else ifs till u get to the defult
else
{
            output = output + ch;
}


Notes:

have to use "||" in place of  "or" in ifs

have to use "==" and not "=" in ifs for compaerson

boolean staments in else ifs will only be check if ifs b4 it are false

else runs if all other ifs b4 are false
