If Goal1 fails, Goal3 is called. In this case, Goal2 is never executed.
Note that this predicate is really a call to ;/2, but since the first argument contains an implicit cut in the first goal, ;/2 behaves like If...Then...Else and only executes one of Goal2 and Goal3.
Also note that:
Goal1 must not contain a !/0. If a !/0 appears in Goal2 or Goal3, it cuts through ->/3.
Since ->/3 has a lower precedence than ,/2, a call to ->/3 should always be enclosed in parentheses.
Success: [eclipse]: X = 1, (X == 1 -> write(a); write(b)). a X = 1 yes. [eclipse]: fail->write(not_me); write(me). me yes. [eclipse]: [user]. p(1). p(2). q(1). q(3). r(2). r(3). user compiled 408 bytes in 0.00 seconds yes. [eclipse]: p(X)->q(Y);r(Y). X = 1 Y = 1 More? (;) % p/1 is cut; q/1 isn't. X = 1 Y = 3 yes. [eclipse]: p(3)->q(2);r(2). yes. Fail: [eclipse]: X = 1, (X == 2 -> write(da); write(nyet)). nyet X = _g76 % X is not bound. no. Error: Goal -> write(a); fail. (Error 4). "write(a)" -> true; fail. (Error 5).