title: Batch - How to set and keep variable value for next command with enabledelayedexpansion on
body: <p>If I don't set <code>enabledelayedexpansion</code> on, the variable value inside <code>if</code> block not immediately changed until going outside. But if I set it on, <code>x</code> will be reset back to previous value on next command. </p>
  
  <pre><code>setlocal enabledelayedexpansion
  if defined x (
      set yes=
      set /p yes=Do you want to reset?
      if !yes! == y set x=
  )
  if not defined x set /p x=X:
  </code></pre>
  
  <p>All that I want is just I don't want</p>
  
  <ol>
  <li>Value changed back on next command </li>
  <li>Value not changed immediately</li>
  </ol>
  
  <hr>
  
  <p>Thank you @<strong>Mofi</strong> for the answer. Your solutions worked but I have to remove the <code>setlocal EnableExtensions DisableDelayedExpansion</code> first which I have to find out why. So the lesson is we cannot immediately read the new value of a variable that just set within the same command including inside an expansion block without <code>EnableDelayedExpansion</code>. And <code>EnableDelayedExpansion</code> must be enabled and ended locally to not mess with global variable. I take the one with <code>goto</code> but I use <code>call</code> and <code>exit</code> instead.</p>