gpt4 book ai didi

dart - 如果条件不符合,Dart会继续切换到下一个案例

转载 作者:行者123 更新时间:2023-12-03 04:35:52 24 4
gpt4 key购买 nike

我有一些发言:

enum Fruit { mango, apple }

if (currentFruit) {
case Fruit.mango:
if (someCondition) {
// do something
} else {
// Continue to next case <--
}
break;
case Fruit.apple:
if (someCondition) {
// do something
} else {
// Continue to next case <--
}
break;
}
如何在不中断开关的情况下继续进行下一个案例?
当我删除 break语句时,它会产生一个错误。

最佳答案

您可以为每个语句创建标签,并指向要继续的语句:

switch (currentFruit) {
mango: //This is a label
case Fruit.mango:
if (someCondition) {
// do something
} else {
continue apple; // Switch to the "apple" case
}
break;
apple: //This is a label
case Fruit.apple:
if (someCondition) {
// do something
} else {
continue mango; // Switch to the "mango" case
}
break;
}

关于dart - 如果条件不符合,Dart会继续切换到下一个案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64139407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com