Three patterns to use “if else” statement in dos/batch scripts

  • Pattern #1
@echo off
set var=b
if "%var%" EQU "a" (echo 1) else if "%var%" EQU "b" (  echo 2) else if "%var%" EQU "c" (  echo 3)
  • Pattern #2
@echo off
set var=b
if "%var%" EQU "a" (
  echo 1
) else if "%var%" EQU "b" (
  echo 2
) else if "%var%" EQU "c" (
  echo 3
)
  • Pattern #3
@echo off
set var=b
if "%var%" EQU "a" (
  echo 1
) ^
else if "%var%" EQU "b" (
  echo 2
) ^
else if "%var%" EQU "c" (
  echo 3
)

Leave a Comment