Reputation: 299
Is there anything in Prolog that works like a for loop and if then condition?
Upvotes: 4
Views: 4698
Reputation: 40768
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.
Upvotes: 11
Reputation: 133639
If you are looking for such kinds of statements then you are not thinking in Prolog :)
Just kidding, by the way there aren't plain translation or for and if/else, but you can think about how they should be in prolog:
Upvotes: 8