China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 15:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] In the example below, how do I assign to multiples of 10? View 1,967 Replies 16
Original Poster Posted 2008-08-10 11:59 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
For /L %%f in (1,1,31) Do if %%f == an integer multiple of 10 (echo multiple of 10) else (echo %%f)

pause

Also:
I originally planned to use if %%f ==%%f/10*10, but unfortunately it won't accept it.

[ Last edited by lummox on 2008-8-10 at 09:17 PM ]
Floor 2 Posted 2008-08-10 12:22 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Floor 3 Posted 2008-08-10 12:32 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
Thanks to the friend in the previous post.
I read the thread you mentioned and tested it, but it still won't run. Please advise further.
Floor 4 Posted 2008-08-10 17:26 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
Still waiting for an answer...
Floor 5 Posted 2008-08-10 18:51 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Did you see my reply in 'post #7' of that thread?
Floor 6 Posted 2008-08-10 19:10 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
I saw it:

'post #5':


CODE: [Copy to clipboard]
--------------------------------------------------------------------------------

for/l %f in (1,1,20) if %@eval[%f %% 5]==0 echo %f

Note: please run it under 4DOS

But I need it to run in the XP DOS window.
Floor 7 Posted 2008-08-10 19:14 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
In the statement above, if %@eval[%f %% 5]==0 won't run.
Floor 8 Posted 2008-08-10 19:19 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Under WindowsXP you can use 4NT or Take Commander; they are 4DOS's successors under Windows.
Floor 9 Posted 2008-08-10 21:21 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
Originally posted by DOSforever at 2008-8-10 07:19 PM:
Under WindowsXP you can use 4NT or Take Commander; they are 4DOS's successors under Windows.


Thanks for your enthusiastic reply :)

My question still hasn't been answered; I only want a solution under DOS.
Floor 10 Posted 2008-08-10 21:37 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
4DOS is under DOS; it is a perfect replacement for COMMAND.
Floor 11 Posted 2008-08-10 23:02 ·  中国 上海 奉贤区 电信
初级用户
Credits 35
Posts 18
Joined 2008-08-10 22:34
17-year member
UID 123138
Gender Male
Status Offline
First method: based on the fact that multiples of 10 all have 0 in the ones place, use SET to extract the ones digit and then test it (not general-purpose):
@echo off&setlocal enabledelayedexpansion
for /L %%f in (1,1,31) Do (set a=%%f&if !a:~-1! equ 0 (echo %%f is a multiple of 10) else (echo %%f))
pause

Second method: use % for the remainder operation, then test it (general-purpose; for example, if you want to output multiples of 3, that also works):
@echo off&setlocal enabledelayedexpansion
for /L %%f in (1,1,31) Do (set /a a=%%f%%10&if !a! equ 0 (echo %%f is a multiple of 10) else (echo %%f))
pause

[ Last edited by shqf on 2008-8-10 at 11:04 PM ]
Floor 12 Posted 2008-08-11 02:06 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
Here's the situation: I wrote a batch file and need to use a line of code similar to the one in the question. Although this line can certainly be implemented with some other group of statements, to me that would be equivalent to foreseeing the problem and avoiding it, rather than solving it, so that's why I came here to ask.
Floor 13 Posted 2008-08-20 17:23 ·  中国 山西 太原 迎泽区 联通
初级用户
Credits 28
Posts 14
Joined 2008-02-29 12:36
18-year member
UID 111702
Gender Male
Status Offline
Thanks to the friend in post #11 for the reply, but it still won't run.
Floor 14 Posted 2008-08-21 07:07 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
@echo off&setlocal EnableDelayedExpansion

for /L %%a in (1,1,31) do (
set /a re=%%a%%10
if "!re!" == "0" (echo %%a is an integer multiple of 10) else (echo %%a)
)
pause
Floor 15 Posted 2008-08-22 09:59 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Save the code from post #14 as xxx.bat
Double-click to run it
Forum Jump: