Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if -then -else question

Status
Not open for further replies.

roykw

Programmer
Dec 8, 2010
2
GR
Hello,

i am a newbie and i have the C-like code:
------
if( x > 10){
x = x + 5 - y;
y = x;
}else{
y = 0;
x = 0;
}
------

and i would to figure how the above code would be in prolog.
So, i was trying :
------
( X > 10
-> X is X + 5 - Y,
Y is X
;
Y is 0,
X is 0
) .
------

but i am not certain, is the line "X is X + 5 - Y" correct?

Thank you.
 
moreover, if we had

if ( x > 10 + y)
/*code*/

in prolog it would be like the code below ?

( X > 10 + Y
/*code*/
).

 
X is X + 5 - Y fails when Y is different of 5.
In SWI-Prolog you can translate if then else by
Code:
(X > Y+10 -> <code-when-true>; <code-when-false>)
Care of parenthesis.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top