Board logo

标题: [讨论]关于 Call 的问题 [打印本页]

作者: quya     时间: 2008-6-3 10:11    标题: [讨论]关于 Call 的问题


call :test
ECHO After "call", this wil be executed.

:test
echo Just a test

REM 难道一定要把 :test 放在最后或者使用 Goto语句才能不执行下边语句

echo I don't want this to be executed inside "test", it should be executed after "call".

作者: zh159     时间: 2008-6-3 10:42

call :test
ECHO After "call", this wil be executed.
goto :eof

:test
echo Just a test
goto :eof

echo I don't want this to be executed inside "test", it should be executed after "call".

作者: bat-zw     时间: 2008-6-3 11:11
1 :: echo I don't want this to be executed inside "test", it should be executed after "call".
2 rem echo I don't want this to be executed inside "test", it should be executed after "call".
3 设立个条件,加在前面:
set /a n+=1&call :test
ECHO After "call", this wil be executed.
goto :eof
:test
echo Just a test
if %n% lss 2 goto :eof
echo I don't want this to be executed inside "test", it should be executed after "call".
以上代码当call :test被执行一次以上后,每次将执行后面的echo I don't want this to be executed inside "test", it should be executed,第一次时不会执行。
作者: quya     时间: 2008-6-3 14:15
谢谢各位, 这证实了"Call" 调用标签的局限性.

不像高级语言中可以用 END Procedure 之类来表示一个子程序的结束.

看来只能用GOTO 来解决, 或者放在最后.

三楼技巧虽好, 但似乎脱离了本贴的主题. 有点杀鸡用牛刀的感觉. 不过说实话, 我编不出类似三楼的代码, 如果我从来没看过这样的代码.
作者: jia332     时间: 2008-6-3 18:13
没意思
call 有它的作用,goto也有它的作用