TTL Control commands-ALL

本文详细介绍了编程中常见的控制结构,如for、while循环,break、continue、call、if-else等在各种编程语言中的使用示例,以及一些辅助指令如pause、return和包含文件等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

–break

退出循环
退出“for”和“while”循环。

 示例:
for i 1 10
	yesnobox 'quit from loop?' 'Tera Term'
 	 if result break
	next

while 1
  recvln
  strcompare inputstr "OK"
  if result=0 then
    break
  else
    sendln "abc..."
  endif
endwhile

–call

call <label>

调用子程序。

示例:
:sub
messagebox "Now I'm in sub" "test"
return

messagebox "I'm in main." "test"
call sub
messagebox "Now I'm in main" "test"
end

–continue

将控制立即转移到循环的下一次迭代。

示例:
a=0
b=0
while a<5 
    a=a+1
    if a>2 then
        continue
    endif
    b=b+1
endwhile

sprintf2 var "a=%d b=%d" a b
dispstr var
;a=5 b=2

–do, loop

循环

示例:
; Repeat ten times.
i = 10
do while i>0
    i = i - 1
loop

; Send clipboard content.
offset = 0
do
    clipb2var buff offset
    if buff > 0 send buff
    offset = offset + 1
loop while result = 2

–end

end

退出宏的执行。

– execcmnd

execcmnd <statement>

执行ttl 命令

–exit

返回到主文件。

–for, next

; Repeat ten times.
for i 1 10
  sendln 'abc'
next

; Repeat five times.
for i 5 1
  sendln 'abc'
next

–goto

goto <label>

跳转到一个标签,

; Jump to the next line of the ':label'.
goto label
...
...
...

:label
send 'abc'

–if, then, elseif, else, endif

if a=1 then
  b = 1
  c = 2
  d = 3
endif

if i<0 then
  i=0
else
  i=i+1
endif

if i=1 then
  c = '1'
elseif i=2 then
  c = '2'
elseif i=3 then
  c = '3'
else
  c = '?'
endif

–include

include '<include file name>'

将控制移动到包含文件。

–mpause

mpause

暂停,后续时间是以ms为单位

–pause

pause

暂停,后续时间是以s为单位

–return

退出子例程并返回到主例程。

–until, enduntil

示例:
; Repeat ten times.
i = 1
until i > 10
  i = i + 1
enduntil

–while, endwhile

示例:
; Repeat ten times.
i = 10
while i>0
  i = i - 1
endwhile
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值