For Loop on Windows Batch

前端 未结 2 1027
别跟我提以往
别跟我提以往 2021-01-29 05:33

I am doing some batch practice and I am trying to do a loop to go backwards and count the numbers from 110 to 100, but only the even numbers. I almost got it to work, but for so

2条回答
  •  爱一瞬间的悲伤
    2021-01-29 06:19

    Try changing %totalCount% to !totalCount!. Therefore, the code should look like this:

    echo off
    setlocal enabledelayedexpansion
    
    set /a totalCount = 0
    
    for /l %%x in (110, -2, 100) do (
       set /a totalCount = !totalCount! + %%x
    )
    
    echo total is !totalCount!
    

提交回复
热议问题