中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-09 14:39
47,811 topics / 349,896 posts / today 1 new / 48,254 members
DOS批处理 & 脚本技术(批处理室) » [Help] In the example below, how do I assign to multiples of 10?
Printable Version  1,964 / 16
Floor1 lummox Posted 2008-08-10 11:59
初级用户 Posts 14 Credits 28
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 ]
Floor2 DOSforever Posted 2008-08-10 12:22
金牌会员 Posts 2,239 Credits 4,639
Floor3 lummox Posted 2008-08-10 12:32
初级用户 Posts 14 Credits 28
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.
Floor4 lummox Posted 2008-08-10 17:26
初级用户 Posts 14 Credits 28
Still waiting for an answer...
Floor5 DOSforever Posted 2008-08-10 18:51
金牌会员 Posts 2,239 Credits 4,639
Did you see my reply in 'post #7' of that thread?
Floor6 lummox Posted 2008-08-10 19:10
初级用户 Posts 14 Credits 28
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.
Floor7 lummox Posted 2008-08-10 19:14
初级用户 Posts 14 Credits 28
In the statement above, if %@eval[%f %% 5]==0 won't run.
Floor8 DOSforever Posted 2008-08-10 19:19
金牌会员 Posts 2,239 Credits 4,639
Under WindowsXP you can use 4NT or Take Commander; they are 4DOS's successors under Windows.
Floor9 lummox Posted 2008-08-10 21:21
初级用户 Posts 14 Credits 28
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.
Floor10 DOSforever Posted 2008-08-10 21:37
金牌会员 Posts 2,239 Credits 4,639
4DOS is under DOS; it is a perfect replacement for COMMAND.
Floor11 shqf Posted 2008-08-10 23:02
初级用户 Posts 18 Credits 35
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 ]
Floor12 lummox Posted 2008-08-11 02:06
初级用户 Posts 14 Credits 28
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.
Floor13 lummox Posted 2008-08-20 17:23
初级用户 Posts 14 Credits 28
Thanks to the friend in post #11 for the reply, but it still won't run.
Floor14 lxmxn Posted 2008-08-21 07:07
版主 Posts 4,938 Credits 11,386
Floor15 HAT Posted 2008-08-22 09:59
版主 Posts 5,017 Credits 9,023
Save the code from post #14 as xxx.bat
Double-click to run it
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023