# Loop: remove the characters at the beginning

**URL:** <https://swi-prolog.discourse.group/t/loop-remove-the-characters-at-the-beginning/3087>\
**Category:** Help!\
**Created:** [October 23, 2020, 6:41am UTC](https://swi-prolog.discourse.group/t/loop-remove-the-characters-at-the-beginning/3087 "2020-10-23T06:41:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrologAxel](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PrologAxel](https://swi-prolog.discourse.group/u/PrologAxel)\
**Post date:** [October 23, 2020, 6:41am UTC](https://swi-prolog.discourse.group/t/loop-remove-the-characters-at-the-beginning/3087/1 "2020-10-23T06:41:16Z")

</div>

Hello.

```prolog
loop_entry(A,[Head|List],X) :-
  print(List),
Head == A,
  loop_entry(A,[List],X).

```

```prolog
?- loop_entry(a,[a,a,a,a,b,c,d,e,f],X).

```

I get the result:

```prolog
[a,a,a,b,c,d,e,f][]
false.

```

But I want the result:

```prolog
b,c,d,e,f

```

I want to delete all a’s at the beginning of the list.  
I think : Head == A,  
is the problem.

Does not work, too:

```prolog
loop_entry(A,[H|L],V) :-
   L \== A.

loop_entry(A,[Head|List],X) :-
  print(List),
  loop_entry(A,[List],X).

```

L == A. For some reason He cannot compare characters?

Thanks

---

<div class="post-metadata">

**Author:** ![volker-wysk](https://avatars.discourse-cdn.com/v4/letter/v/858c86/32.png) [@volker-wysk](https://swi-prolog.discourse.group/u/volker-wysk)\
**Post date:** [October 23, 2020, 7:26am UTC](https://swi-prolog.discourse.group/t/loop-remove-the-characters-at-the-beginning/3087/2 "2020-10-23T07:26:34Z")

</div>

> > ![](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/8/8dff0329b3e8d04714d42f43d328bf504a72f718.png "PrologAxel") | [PrologAxel](https://swi-prolog.discourse.group/u/prologaxel)  
> > October 23 |
> > 
> > - | - |
> 
> Hello.
> 
> `
> 
> ```prolog
> loop_entry(A,[Head|List],X) :-
> 
> ```
> 
> ```prolog
> print(List),
> 
> ```
> 
> ```prolog
> Head == A,
> 
> ```
> 
> ```prolog
> loop_entry(A,[List],X).
> 
> ```
> 
> `
> 
> ?- loop\_entry(a,[a,a,a,a,b,c,d,e,f],X).
> 
> I get the result:  
> [a,a,a,b,c,d,e,f]  
> false.
> 
> But I want the result:  
> b,c,d,e,f
> 
> I want to delete all a’s at the beginning of the list.  
> I think : Head == A,  
> is the problem.
> 
> Does not work, too:
> 
> loop\_entry(A,[H|L],V) :-  
> L == A.
> 
> loop\_entry(A,[Head|List],X) :-  
> print(List),  
> loop\_entry(A,[List],X).
> 
> L == A. For some reason He cannot compare characters?

This should be “Head = A”, not “Head == A”.

Cheers  
Volker

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [October 23, 2020, 1:25pm UTC](https://swi-prolog.discourse.group/t/loop-remove-the-characters-at-the-beginning/3087/3 "2020-10-23T13:25:22Z")

</div>

The following seems what you have in mind. If so, I’m happy.

```prolog
% ?- loop_entry(a, [a,a,a,b,c], X).
%@ X = [b, c].
% ?- loop_entry(a, [b,c], X).
%@ X = [b, c].

loop_entry(A, [A | List], X) :-!, loop_entry(A, List, X).
loop_entry(_, List, List).

```

K.M.

---

<div class="post-metadata">

**Author:** ![PrologAxel](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@PrologAxel](https://swi-prolog.discourse.group/u/PrologAxel)\
**Post date:** [October 23, 2020, 6:35pm UTC](https://swi-prolog.discourse.group/t/loop-remove-the-characters-at-the-beginning/3087/4 "2020-10-23T18:35:29Z")

</div>

Thank you. This was exactly what I was looking for.
