中国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 06:25
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » [Why?] In a DO……LOOP loop, why does it loop back in reverse after finishing?
Printable Version  1,250 / 7
Floor1 Vampire Posted 2007-04-26 11:53
初级用户 Posts 78 Credits 176
The code is as follows. Please ask an expert to help analyze it... eagerly waiting


  1. @echo off
  2. setlocal enabledelayedexpansion
  3. color 0e
  4. mode con lines=20 cols=60
  5. set count=-1
  6. set a=Today is another healthy, happy, positive, and progressive day. Lift your head, oh hey, walk forward, oh hey... ——Breathe the New World
  7. :loop
  8. set /a count+=1
  9. call set temp=%%a:~!count!,1%%
  10. if "%temp%"=="" (
  11. goto out
  12. ) else (
  13. call set /p=%%a:~!count!,1%%<nul
  14. call :sound "%temp%"
  15. )
  16. :sound
  17. mshta vbscript:createobject("sapi.spvoice").speak(%1)(window.close)
  18. goto loop
  19. :out
  20. echo.
  21. pause>nul
Posted by Vampire: 2007-04-25 22:41


[ Last edited by Vampire on 2007-4-25 at 11:03 PM ]
Floor2 lxmxn Posted 2007-04-26 12:06
版主 Posts 4,938 Credits 11,386
Try adding a goto :EOF below mshta.
Floor3 Vampire Posted 2007-04-27 02:59
初级用户 Posts 78 Credits 176
Thanks for moderator lxmxn's reply. If I add goto :EOF below mshta, it gives an error; if I add it below :out, it still loops back.
Floor4 lxmxn Posted 2007-04-27 03:55
版主 Posts 4,938 Credits 11,386
Floor5 zh159 Posted 2007-04-27 07:35
金牌会员 Posts 1,467 Credits 3,687
Floor6 Vampire Posted 2007-04-29 05:20
初级用户 Posts 78 Credits 176
Thanks to the two posters above for the replies, I learned two more things. I've been a bit busy these past two days so I read it slowly, please forgive me. One more question: in the help file, goto :eof is explained like this:

If command extensions are enabled (the default), and you use a goto command with the target label :EOF, control can be transferred to the end of the current batch script file without defining the label, and then the batch script file is exited.

But then why can it still continue executing the loop? Could it be because it is only a called procedure, and has no authority to end the global environment?

[ Last edited by Vampire on 2007-4-28 at 04:27 PM ]
Floor7 flamemperor Posted 2007-09-13 17:37
初级用户 Posts 29 Credits 66
After analyzing it, I feel the OP's code is wrong at the goto back to loop in :sonud, because at that point the sonud subroutine has not ended yet. Only when temp finally becomes empty does it reach out, and at that time the last sound finishes, then it backs out one by one.

eof can only exit the current subroutine, right?

Not sure whether that's correct.

[ Last edited by flamemperor on 2007-9-13 at 05:58 PM ]
Floor8 Vampire Posted 2008-07-21 19:14
初级用户 Posts 78 Credits 176
The poster above got it exactly right...
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023