WordPress Insert ads after every 5th post

Hi I want to create a single archive page where every custom post will get displayed on click of a button and after every 5th post I can add an Ad image which can be fetched as another posts type

I can get the currentpost index and able to add an ad on 5th position but I am unable to continue it further.

Here is my code

Can anyone please help.

Thanks in advance