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

  • Home
  • SEARCH
  • 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 7722475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:11:04+00:00 2026-06-01T04:11:04+00:00

Assignments (i.e. set statements) made within an if block are not realized until after

  • 0

Assignments (i.e. set statements) made within an if block are not realized until after the if block. So, in other words, you can’t rely on variable assignment within an if block. How to fix this?

  • 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-01T04:11:06+00:00Added an answer on June 1, 2026 at 4:11 am

    Assignments in IF or FOR blocks are realized immediately. What is not properly realized is the sustitution of variable values enclosed in percent signs. You must note that a %variable% value is replaced before executing the line. For example:

    set var=Old value
    set var=New value & echo %var%
    

    Previous commands show: “Old value”. The way to solve this problem is via Delayed Expansion, that is, enclose the variable in exclamation marks instead percents and add a setlocal … command at beginning. That is:

    setlocal EnableDelayedExpansion
    set var=Old value
    set var=New value & echo !var!
    

    This way, !var! value is replaced until echo !var! command is executed (delayed expansion) and after the previous set command is executed, so previous commands show: “New value”.

    This same dicussion apply to any variable inside parentheses. For example:

    set var=Old value
    if 1 == 1 (
       set var=New value
       echo %var%
    )
    

    …is wrong because %var% value is expanded just once before executing the whole IF (or FOR). You must use:

    setlocal EnableDelayedExpansion
    set var=Old value
    if 1 == 1 (
       set var=New value
       echo !var!
    )
    

    Type SET /? for further details.

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

Sidebar

Related Questions

Can you suggest some good Javascript assignments/homework to C programmers , who are not
I've been led to believe that for single variable assignment in T-SQL, set is
I would like to automatically align lines of python variable assignments in vim. For
I'm getting a Variable TMP_1 might not have been initialized error. Here's the snippet:
(Before anyone asks, this is not homework.) I have a set of workers with
Can I get the variable from another class if I do it like this
The basis of the assignment is to use the if/else if statements to set
How to set entire HTML in MSHTML? I am trying using this assignment: (Document
One of the assignments in my algorithms class is to design an exhaustive search
I have a lot of assignments where I have to continually update a Makefile

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.