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 8433319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:21:17+00:00 2026-06-10T06:21:17+00:00

I have a for loop in a batch file that looks like this: for

  • 0

I have a for loop in a batch file that looks like this:

for %%y in (100 200 300 400 500) do (
    set /a x = y/25     
    echo %x%
)

The line:

set /a x = y/25

Doesn’t seem to be doing any division. What is the correct syntax for dividing each y by 25? I only need the integer result from this division.

  • 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-10T06:21:18+00:00Added an answer on June 10, 2026 at 6:21 am

    Environment variables need not be expanded to use in a SET /A statement. But FOR variables must be expanded.

    Also, even if your computation worked, the ECHO would fail because percent expansion takes place when a statement is parsed, and the entire FOR construct is parsed at once. So the value of %x% would be the value as it existed before the loop is executed. To get the value that was set within the loop you should use delayed expansion.

    Also, you should remove the space before the assignment operator. You are declaring a variable with a space in the name.

    @echo off
    setlocal enableDelayedExpansion
    for %%A in (100 200 300 400 500) do (
      set n=%%A
    
      REM a FOR variable must be expanded
      set /a x=%%A/25
    
      REM an environment variable need not be expanded
      set /a y=n/25
    
      REM variables that were set within a block must be expanded using delayed expansion
      echo x=!x!, y=!y!
    
      REM another technique is to use CALL with doubled percents, but it is slower and less reliable
      call echo x=%%x%%, y=%%y%%
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set that looks like: Files Batch filepath1.txt One filepath2.txt One
I would like to set up a simple batch file that would loop through
I have loop and each iteration of Hash looks like this: [1, {:clid=>1, :nvz=>4,
i have a sub that looks like this: Sub open_esy(filename, p As String, p1
I have a simple FOR loop inside of a batch file I'm creating that
I have following batch file code: @echo off SET INSTALL_PATH=c:\program files\ :ask_again if exist
I have a batch file which initializes variables via SET inside a for loop,
I have this batch file @ECHO OFF ECHO Please Enter Path of the View,
I have a file that look like this: 1 543423 34354 2 5654656 3423
I have a windows batch file that does this: for %%s in (*.sql) do

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.