Quote:
Originally Posted by srini_vk Hi
I've to do multiple commands after if. How do I do that.
For e.g.,
IF a == 1 (
echo Its success.
Call abc
..
..
)
Thanks,
Srini |
You do it just like you have it shown.
If Condition (
multiple statements executed if Condition true
)
Works with If Else or nested If statements as well
If Condition (
multiple statements executed if Condition is true
) Else
(
multiple statements executed if Condition False
) Quote:
Originally Posted by midders Code: IF string1==string2 goto label1
IF string1==string3 goto label2
goto end
:label1
rem do lots of stuff here
goto end
:label2
rem do lots of other stuff here
goto end
:end
rem end
|
While it's mostly a matter of preference if you use goto statements and labels instead of parentheses, the above has one potential problem: if string2 and string3 happen to be
equal, you may want to execute the commands under label2 as well as label1, which the above doesn't allow for.
The following form will catch that particular case. If string2 and string3 aren't equal, it just falls through the 2nd If statement, and the goto statements and labels aren't needed. This only requires 6 lines minimum instead of 9 lines minimum:
Code:
If string1==string2 (
Stuff to do if string1=string2
)
If string1==string3 (
Stuff to do if string1=string3
)
It's also the easiest way to nest If statements
Code:
If Condition1 (
Echo Condition is true, let's check another
If Condition2 (
Echo This is displayed only if Condition1 and Condition2 are both true
) Else (
Echo This is displayed only if Condition1 is True and Condition2 is False
)
Goto _Label1
)
Echo This is executed only if Condition1 is False
Goto :EOF
:_Label1
Echo This is executed only if Condition1 is True
HTH
Jerry