define two variables are not equal in Prolog: X \= Y not(X = Y) \+ (X = Y) ...

The simplest way to solve the problem would be to constrain A and B further and force one to be "greater" than the other. I'm not sure exactly if this is the syntax in Visual Prolog, but try this. Note the use of A > B instead of A <>...

What you have is very close to correct, but requires a little more constraint. The existing clause is recursing into negative values of Limit. Here's a minor update which should resolve that issue, along with some minor tweaks: check(0, 0, 1). check(N, 0, 0) :- N > 0. % Added...