Coldfusion 在开关内调用另一个案例

发布于 2024-12-20 05:19:39 字数 302 浏览 0 评论 0原文

我有一个像这样的开关(用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜声 2024-12-27 05:19:39

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.

憧憬巴黎街头的黎明 2024-12-27 05:19:39

正如 Adam 所解释的,这是可能的,这里有一些代码展示了如何操作:

something = "stuff";
test = "more stuff";

switch (something) {
case "stuff":
  if(test eq "more stuff"){
    writeOutput("<p>Something</p>");
    break;
  } 
case "other":
  writeOutput("<p>something Else</p>");
  break;
}

更改“something”和“test”的值以查看不同的结果。在 cfscript 中使用开关时,如果没有“中断”,那么 ColdFusion 将继续处理案例,直到遇到一个。

As Adam explained, it is possible, here is some code to show how:

something = "stuff";
test = "more stuff";

switch (something) {
case "stuff":
  if(test eq "more stuff"){
    writeOutput("<p>Something</p>");
    break;
  } 
case "other":
  writeOutput("<p>something Else</p>");
  break;
}

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.

飞烟轻若梦 2024-12-27 05:19:39

据我所知这是不可能的。您需要使用 if else 语句或嵌套的 is/else,而不是 switch。

something = "other";

if (something eq "stuff" and 1 eq 2) {
    writeDump("hello");
} else if (something eq "other") {
    writedump("other");
}

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.

something = "other";

if (something eq "stuff" and 1 eq 2) {
    writeDump("hello");
} else if (something eq "other") {
    writedump("other");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文