I see, I had thought if one asks for forgiveness twice and repeats the sin twice, then god would not forgive him a third time

No that is not correct. Allah is the most merciful and one of the great sins is to despair of the mercy of Allah.