Search code examples
batch-fileif-statementcmdgoto

Using GOTO inside an IF statement


   if  %_var%==1 (
    goto :group1
) else if  %_var%==2 (
    goto :group2
) else (
    goto :groupOthr
)

What am I doing wrong here ? I keep getting the error -

( was unexpected at this time.

Tried doing this -

   if  %_var%==1 (goto :group1
) else if  %_var%==2 (goto :group2
) else (goto :groupOthr
)

And then I get -

(goto was unexpected at this time.


Solution

  • if  "%_var%"=="1" (
        goto :group1
    ) else if  "%_var%"=="2" (
        goto :group2
    ) else (
        goto :groupOthr
    )
    

    Just got it right. Found the answer here - goto unexpected with blank choice