go - 缩短||或者如果Golang中的语句

标签 go shorthand

学习Golang,想知道是否有更短的编写方法

            if tiletype == 0 || tiletype == 2 {
                levelmap[passage1block] = "wall"
            } else {
                levelmap[passage1block] = "floor"
            }
在想这是办法,尽管它不起作用
                if tiletype ==0,2 {
            levelmap[passage1block] = "wall"
            } else {
                levelmap[passage1block] = "floor"
            }

最佳答案

您可以编写一个switch-case语句:

switch tiletype {
   case 0,2: levelmap[passage1block]="wall"
   default: levelmap[passage1block]="floor"
}

关于go - 缩短||或者如果Golang中的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62960362/

相关文章:

jquery - jQuery 库如何使用 $ 代替 "JQuery"来引用对象?

mysql - Unicode 编码 - 错误 1366 : Incorrect string value: '\xF0' for column

google-app-engine - aetest.NewContext() 是否需要参数?

go - 如何解释这个程序实现接口(interface)

javascript - If true … else 速记

ruby - 将项目添加到 Ruby 中的数组,即使变量不存在

c# - 如何通过速记 "if-else"结果打破循环?

javascript - JS - 创建对象速记

Golang 计时器过期 VS 停止之间的区别?

go - 创建处理程序如何工作?