Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:59:01+00:00 2026-06-10T10:59:01+00:00

FOR /L %%i IN (1,1,100) DO ( choice echo %ErrorLevel% ) %ErrorLevel% is always

  • 0
FOR /L %%i IN (1,1,100) DO (
    choice
    echo %ErrorLevel%
    )

%ErrorLevel% is always 0 no matter what choice you enter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:59:02+00:00Added an answer on June 10, 2026 at 10:59 am

    You are checking the errorlevel the wrong way.

    Variables and commands inside a bracket pair like this…

    (
      command1
      command2
      command3
    )
    

    …act like they were run on a single line, like this command1 & command2 & command3.

    Try this at the command line.

    choice & echo %errorlevel%
    

    If you execute the above command more than once, you will see that the previous errorlevel is echoed, not the current one.

    Or try this on the command line:

    set x=yes
    ( echo %x%
      set x=no
      echo %x%
    )
    

    Your output will be:

    yes
    yes
    

    Just as if you’d entered echo %x% & set x=no& echo %x%

    I like to think of it as the system doesn’t have the time to update the variables. (Though it’s more accurate to say that the variables only get updated after the entire line is executed.) This is true with all variables, not just the errorlevel.

    To make variables in for loops work normally you need to call an internal label in your batch file (or an external batch file) like this.

    @echo off
      FOR /L %%i IN (1,1,100) DO call :dostuff %%i
    goto :eof
    
    :dostuff
      choice /m "Question #%1"
      echo %ErrorLevel%
    

    ==================================== Solution To Question Below

    Alternatively, Microsoft has created a method for accessing the current value of variables inside of a bracket pair, they call it ‘Delayed Expansion’ because the line of code is interpreted twice.

    To activate this mode you use the setlocal command with the enableDelayedExpansion switch, and access the variables with the ! character like this. FYI endlocal turns off the effects.

    @echo off
    setlocal enableDelayedExpansion
    for /L %%i in (1,1,100) do (
      choice /m "Question #%%i"
      echo !ErrorLevel!
    )
    endlocal
    

    As you can see my first example is easier to code, but my second example is easier to read. Whichever method you use will depend upon your needs and re-usability.

    The setlocal command also has the effect of creating temporary variables that die after the endlocal command. This means you don’t need to delete them when your batch file ends, and reverts any variables you changed during execution back to their original values. This is nice because you don’t have to worry about ‘stepping on’ any preexisting variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You have this code in Javascript (even though language choice does not matter): var
100['toString'] //does not fail 100.toString //fails why? 100.toString is not same as 100.toString() .
100%I'm modifying an older website for a client that uses Ext-JS 1.1 and I'm
I have around 100 models, from MCMCglmm, that give output similar to this: >
I'm not 100% sure if the problem is with openTK but it is the
I want to get 100 and example from this string ?connect:100/username:example/ I searched in
Preface: I am 100% new to the Flash and ActionScript world, doing research for
I have a list: ['100 ug/ml', '50 ug/ml', '25 ug/ml', '12.5 ug/ml', '6.25 ug/ml',
I'm not 100% sure how I should word this question but I'll try my
I have given 100% width to input box to fix to the browser width

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.