Beginner's question: findall with predicate that does not "return" anything

Is there a more elegant way to invoke all “solutions” of pred/0?

?- [user].
|: pred :- writeln(1).
|: pred :- writeln(2).
|: pred :- writeln(3).
|:
% user://1 compiled 0.02 sec, 3 clauses
true.

?- pred.
1
true ;
2
true ;
3
true.

?- findall(_, pred, _).
1
2
3
true.

A failure driven loop, or even better, forall/2, which nicely separates generator and side effect.

Just to explain a bit more:

?- forall(pred, true).
1
2
3
true.

true/0 is used here, to indicate success without additional action - because the desired action is done by pred.

Just to explain even more, don’t do that unless you have to. Start by reading the docs to forall/2 as those explain how to use the predicate and how it is implemented. There is also some discussion about side effects in particular. It is not clear @mgondan1 if you must have a side effect or if you just happen to show an example with a side effect in it, for demonstration.

If you want the side effect, this seems easy to read and write:

?- forall(between(1, 3, X), writeln(X)).
1
2
3
true.

If you don’t want the side effect then it depends.

Thank you!

It’s actually the side effects that I want to trigger. Each call of pred asserts some facts that I need in the later course.