Coldfusion 在开关内调用另一个案例
我有一个像这样的开关(用 cfscript 编写):
switch (something) {
case "stuff":
if(this eq that){
writeDump("hello");
} else { /* do other? */ }
break;
case "other":
//do something else
break;
}
在我的 else 中,我希望能够告诉它我希望调用“其他”情况。这可能吗? (我似乎记得用其他语言做过这个。)
I have a switch like thus (written in cfscript):
switch (something) {
case "stuff":
if(this eq that){
writeDump("hello");
} else { /* do other? */ }
break;
case "other":
//do something else
break;
}
In my else
, I want to be able to tell it that I want the "other" case to be invoked. Is this possible? (I seem to remember doing this in other languages.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CF 中没有 GOTO 结构,没有。这正是您所要求的。
如果您的 switch 确实如您所指示的那么简单,并且您希望在条件为 false 时跳转到 NEXT 情况,那么您可以做的就是在 true 分支中添加break语句。 if 子句,并且 false 分支中没有break 语句。然后,当错误分支运行时,处理完成后不会退出案例;它将进入下一个案例。
There is no GOTO construct in CF, no. And that's pretty much what you're asking for.
If your switch is really as simple as you indicate, and you want to fall through to the NEXT case when the condition is false, what you could do is to have the break statement in the true branch of the if clause, and have no break statement in the false branch. Then when the false branch runs, processing will not exit the case when it's done; it'll fall through to the next case.
正如 Adam 所解释的,这是可能的,这里有一些代码展示了如何操作:
更改“something”和“test”的值以查看不同的结果。在 cfscript 中使用开关时,如果没有“中断”,那么 ColdFusion 将继续处理案例,直到遇到一个。
As Adam explained, it is possible, here is some code to show how:
Change the values of 'something' and 'test' to see different results. When using a switch in cfscript, if there is no 'break' then ColdFusion will continue processing the cases until it hits one.
据我所知这是不可能的。您需要使用 if else 语句或嵌套的 is/else,而不是 switch。
As far as I'm aware that's not possible. You'll need to use an if else statement, or nested is/else, instead of the switch.