0

I have this block of code which is throwing error : "The syntax is incorrect".

SET "VAR1=UP"
SET "VAR2=UP"

IF ("%VAR1%"=="UP")
(
  IF "(%VAR2%"=="UP")
  ( ECHO "VALUES MATCH")
 ) 

But this keeps throwing error as mentioned above. Is the comparison syntax ( %VAR1%"=="UP") incorrect or there is any issue with Variable declaration?

The function of the code will be: There will be four such If blocks, each will compare the four possible values of the two variables and throw specific display message .

Would really be obliged if anyone can help me in this.

1
  • That is not the correct syntax for the IF command. Open up a cmd prompt and type IF /? to read the help file for the IF command. Commented Aug 28, 2017 at 14:31

1 Answer 1

2
IF ("%VAR1%"=="UP")

The string IF ("%VAR1%" will never equal the string "UP"), regardless of the value of var1 - these parenthesis for part of the comparison, you can't group them as a "Boolean".

IF "%VAR1%"=="UP"

is the correct comparison syntax, BUT

(

Which starts the grouping of the statements to cascade if the comparison is evaluated as true absolutely MUST be on the same physical line as the if.

The same goes for else - the syntax ) else ( must appear just exactly so.

Sign up to request clarification or add additional context in comments.

1 Comment

This has worked.Thanks a lot for your help.Much obliged.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.