swift - Swift等效于while循环与python中的else
问题描述
我有以下用 Swift 编写的代码
if current_game_state == game_state.in_game {
while player_card_values.sum() <= 20 {
for touch: AnyObject in touches {
let point_of_touch = touch.location(in: self)
if hit_label.contains(point_of_touch){
spawn_card()
print("Hit Button Pressed")
}
}
}
else {
if self.player_card_values.sum() == 21 {
print("Player has received BJ!")
self.player_status = person_status.stand
break
}
}
for touch: AnyObject in touches {
let point_of_touch = touch.location(in: self)
if stand_label.contains(point_of_touch){
print("Stand Button Pressed")
player_status = person_status.stand
}
}
}
}
所有内部接触都始于 Spritekit。但由于某种原因,我在尝试编译时遇到了两个错误。
- 闭包表达式未使用,在它说 else 的那一行。不知道为什么,因为表达式没有被使用,因为里面有代码。
- 未标记的中断只允许在循环或开关内部,需要标记的中断才能退出以及 if 或 do。我在这里感到困惑-未标记和标记的中断之间有什么区别?而 else 语句是响应 while 循环,如果 playercardvals 的总和大于 20
解决方案
Swift中没有while ... else ...
,你将不得不重构你的逻辑。
此外,您不想在touchesBegan
您的应用程序内部循环将停止响应!
推荐阅读
- unity3d - 如何使这些 Mocap Animation FBX 与 Unity 配合使用?
- laravel - Dusk 没有加载正确的 .env
- javascript - I can't reference an image in Next.js
- c# - c# QuadTree 正确产生
- java - 修改 JavaFX 手风琴
- c++ - 如何用图像和文本控制 Qt TextArea contentHeight?
- css - 带有语义 UI React 的响应式菜单
- java - Java MySql 连接器版本之间的默认 CHARACTER_SET 和 COLLATION_CONNECTION 更改了吗?
- image - 如何从 URL 获取图像到 Flutter 中的文件?
- javascript - 我需要为“Application Insights for web pages”遥测调用创建一个代理端点(Azure 函数代理失败 CORS 选项调用)