if else if else clause in prolog similar to C/C++

前端 未结 5 779
说谎
说谎 2021-01-18 14:53

In c language i have something like :

if(cond1)
{}
else if(cond2)
{}
else
{}

how is this possible in Prolog?

5条回答
  •  醉梦人生
    2021-01-18 15:02

    (   If1 -> Then1
    ;   If2 -> Then2
    ;   ...
    ;   otherwise
    ).
    

    Note that if-then-else is only necessary if you cannot express the different conditions by pattern matching in different clauses. Everything that can be expressed by pattern matching should be expressed by pattern matching, as this typically leads to more general and also more efficient code.

提交回复
热议问题