效率篇——AppleScript入门2

AppleScript循环:

(*
 *  1. repeat 死循环
 *)
set num to 0
display dialog num

-- 最简单循环,是死循环
repeat
	set num to num + 1
	display dialog num
	if num ≥ 10 then
		exit repeat
	end if
end repeat

 

(*
   2.限定次数的循环 repeat n times  其中n 可以是变量,可以是常量
*)

-- 创建全局变量 num
set num to 0
global num

set n to 6
-- 限定循环n次
repeat n times
	run dialogScript
end repeat

-- 创建自定义脚本
script dialogScript
	set num to num + 1
	display dialog num
end script

 

(*
   3.依次打印 0 ~ 9
*)

set num to 0

-- 直到型循环
(*
repeat until num ≥ 10
	display dialog num
	set num to num + 1
end repeat
*)

-- 当型循环
repeat while num < 10
	display dialog num
	set num to num + 1
end repeat

 

-- 变量循环 
-- 优势:可以调整跨度,by num 可以省略,默认是 1
repeat with i from 0 to 10 by 3
	display dialog i
end repeat

 

-- List循环 
set students to {"张三", "李四", "王五"}

-- 注意这里的i是指针,想要获取内容要用 contents of i 取得
repeat with i in students
	display dialog contents of i
	set (contents of i) to "小明"
end repeat

display dialog "" & students

 

转载于:https://www.cnblogs.com/no1OverTheWorld/p/4420012.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值