Prolog 循环和条件语句? [英] Prolog loops and conditional statements?

查看:50
本文介绍了Prolog 循环和条件语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Prolog 中是否有类似 for 循环和 if then 条件的东西?

Is there anything in Prolog that works like a for loop and if then condition?

推荐答案

if/then/else 可以通过 (->)/2 和 (;)/2 获得:

if/then/else can be obtained with (->)/2 and (;)/2:

(    If ->
     Then
;    Else
)

有时这很有用.一般来说(当条件包含变量时),它会使你的程序不健全和不完整.只要可以用模式匹配来描述条件,就应该改用模式匹配.然后,您不仅可以检查,还可以生成解决方案.

Sometimes this is useful. In general though (when the condition contains variables), it will make your programs unsound and incomplete. Whenever it is possible to describe the conditions with pattern matching, you should use pattern matching instead. You can then not only check but also generate solutions.

这篇关于Prolog 循环和条件语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆