title: How to deal with nested if blocks in BATCH scripts?
body: <p>I have an issue with my batch script likely related to the nested blocks syntax.</p>
  
  <p>I have two scripts: a main script, and a start script in order to start the main one. Both are respectively named "script.bat" and "start.bat" for the example.</p>
  
  <p>Below the scripts (MCVE):</p>
  
  <p>script.bat</p>
  
  <pre><code>@echo off
  set init="%1"
  set bool=%2
  set switch=%3
  if %bool%==true (
      set var=%init:"=%
      set check=false
      if "%switch%"=="I" (
          if "%var%"=="A" set check=true
          if "%var%"=="B" set check=true
          if "%var%"=="C" set check=true
          if "%var%"=="D" set check=true
          if "%var%"=="E" set check=true
          if "%var%"=="F" set check=true
          if "%var%"=="G" set check=true
      )
      if "%switch%"=="II" (
          if "%var%"=="A" set check=true
          if "%var%"=="B" set check=true
          if "%var%"=="C" set check=true
          if "%var%"=="D" set check=true
          if "%var%"=="E" set check=true
      )
      if "%switch%"=="III" (
          if "%var%"=="A" set check=true
          if "%var%"=="B" set check=true
          if "%var%"=="C" set check=true
          if "%var%"=="D" set check=true
          if "%var%"=="E" set check=true
          if "%var%"=="F" set check=true
      )
      if %check%==false set code=1
      if %check%==true set code=0
      if %check%==true set result=%var%
  )
  if %bool%==false echo Skipped!
  if %bool%==false goto quit
  if defined result (
      echo RESULT = %result% [exit code: %code%]
  ) else (
      echo RESULT = NULL [exit code: %code%]
  )
  :quit
  echo.
  pause
  exit
  </code></pre>
  
  <p>start.bat</p>
  
  <pre><code>@echo off
  start script.bat C true II
  start script.bat F true II
  start script.bat B false I
  </code></pre>
  
  <p>Here is the expected results (It should prompt three Windows consoles as below.)</p>
  
  <p>First console:</p>
  
  <pre><code>RESULT = C [exit code: 0]
  
  Press any key to continue...
  </code></pre>
  
  <p>Second console:</p>
  
  <pre><code>RESULT = NULL [exit code: 1]
  
  Press any key to continue...
  </code></pre>
  
  <p>Third console:</p>
  
  <pre><code>Skipped!
  
  Press any key to continue...
  </code></pre>
  
  <p>Instead of that, I have the error below in each of the three consoles:</p>
  
  <pre><code>set was unexpected at this time.
  </code></pre>
  
  <p>Thanks for your help and sorry if my english is inaccurate sometimes.</p>
  
  <p>Have a nice day. :)</p>
  
  <p>EDIT: this problem seems to be not related with the delayed expansions because we have a syntax error here. A "delayed expansion" related issue should lead to a wrong result instead but not a syntax error like in my example.</p>
  
  <p>EDIT 2: after trying with delayed expansions, thats worked! Please, disregard the previous edit.</p>