# Coding problem

**URL:** <https://swi-prolog.discourse.group/t/coding-problem/2897>\
**Category:** Help!\
**Created:** [September 8, 2020, 11:32pm UTC](https://swi-prolog.discourse.group/t/coding-problem/2897 "2020-09-08T23:32:01Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![moraneus](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@moraneus](https://swi-prolog.discourse.group/u/moraneus)\
**Post date:** [September 11, 2020, 4:15pm UTC](https://swi-prolog.discourse.group/t/coding-problem/2897/22 "2020-09-11T16:15:46Z")

</div>

Further to your help, I was tried to do something like this.  
**First of all, thank you for your detailed answers and your patience, I learn a lot from this.** 🙂  
I have this problem that my output is duplicated to many times instead to print one time  
`HERE`  
I know this is not like you told me, I will fix it at the end, according to your explanations.  
In my code I have few facts and then I want to check if `x_lt_y`  
for all `y`  
**If is true, I want to print an `HERE` and then stop with `fail` (Because I want that my program will** **continue to another `check` rule)**  
The first use of `findall` found all the facts that `x_lt_y(a, X)`.  
The second use of `findall` found all the facts that `some_fact_s` of specific name value is bigger then `a` value.  
Hopefully you can help me understand why it’s return back and print the same.  
(I tried to debug but I didn’t understand)

# Code:

```prolog
x_lt_y(a, b).
x_lt_y(a, c).

some_fact_s(b, 5). % (name, start_value)
some_fact_s(c, 6). % (name, start_value)
some_fact_s(a, 1). % (name, start_value)
some_fact_e(a, 2). % (name, end_value)

is_not_empty(List) :- 																	
	member(_,List).

check(A, _a_end) :- 
	findall(B, x_lt_y(A, B), Result),
	format("~k~n", [Result]),
	is_not_empty(Result),
	findall(X, (member(X, Result), some_fact_s(X, _b_start), _b_start > _a_end), Result2),
	is_not_empty(Result2),
	format("[HERE]~n", []),
	fail.

check(A, _a_start) :- 
.
.
.
.

```

# Output:

```prolog
?- check(a, 2).
[b,c]
[HERE]
[HERE]
[HERE]
[HERE]
false.

```

---

_[View the full topic](https://swi-prolog.discourse.group/t/coding-problem/2897)._
