-5

I have the following code and as can be seen that in both the cases I'm using Section = A. But, is there a way to check both 1&2 in "When" so that to avoid more lines of code?

Evaluate INTERFACE
When "1"
   SECTION = "A";
   Break;
When "2"
   SECTION = "A";
   Break;

Any help is highly appreciated and please remember I'm still, learning. Thanks! :)

4

2 回答 2

2

首先:你的代码看起来不像Java、C或Cpp,它与OOP无关,所以更正标签。

问题:在快速搜索之后,Evaluate-When它似乎具有与众所周知switch-case.

switch-case你不能真正拥有OR语句,但你可以通过不使用以下方式为同一个块分配多个值break

char c = 'a';
switch(c){
    case 'a':
    case 'A':
        fooA(); //'a' AND 'A' will land here
        break;
    case 'b':
        fooSmallB(); //only 'b' lands here
    case 'B':
        fooB(); //'b' AND 'B' lands here
        break;
    default:
        fooDef(); //Everything that does not hit any case lands here
}

这模拟了 OR 语句。而且是不可能的。

编辑:我现在看到,语言是人员代码。以前从未听说过,但文档显示:Evaluate-When is not much different than Switch-Case

尽管如此:几乎总是有比 更好的可能性,请参阅此处switch-case迈克尔的第一条评论。

于 2017-02-06T16:31:47.670 回答
0

您的语法和Evaluate语句属于Oracle ERP 中使用的PeopleCode编程语言PeopleSoft

Evaluate 类似于 switch/case 语句,这里是如何根据给定场景在 PeopleCode 中正确使用它的示例。

Evaluate &yourVariable
When = "1"
When = "2"
   Warning "Value is either 1 or 2";
   Break;
When = "3"
   Warning "Value is 3";
   Break;
When = "4"
   Warning "Value is 4";
   Break;
When-Other
   Warning "Unexpected value."
End-Evaluate;

是有关 PeopleCode 评估语句的详细官方文档。

于 2019-07-02T05:17:51.070 回答