0

MiniZinc チュートリアルで、endif一連の条件文の最後にキーワードが何度も繰り返されていることに気付きました。この冗長な構文の代わりに、MiniZinc で switch ステートメントを書くことは可能ですか?

たとえば、この一連の条件文をもっと簡潔に書きたいと思います。

predicate examplePredicate(var int:x, int:s) =
if s == 1
    % some code goes here
else if s == 2 then
    % some code goes here
else if s == 3 then
    % some code goes here
else if s == 4 then
    % some code goes here
else
    % some code goes here
endif endif endif endif;
4

1 に答える 1

3

複数の「endif」は必要ありません。「else if」の代わりに「elseif」を使用できます。

predicate examplePredicate(var int:x, int:s) =
  if s == 1
     % some code goes here
elseif s == 2 then
     % some code goes here
elseif s == 3 then
     % some code goes here
elseif s == 4 then
     % some code goes here
else
     % some code goes here
endif;

注: (単純な) ルックアップ テーブルが必要な場合は、代わりにグローバル制約 "テーブル" を使用できます。例については、MiniZinc チュートリアルのセクション 4.1.3 を参照してください。

于 2015-09-26T05:06:37.063 に答える