Loop certain number of times then do action

Then how can you be sure of the state of relayPin when the relay is not turned on ?

We are now nearly 20 replies into this topic and you have made changes to the sketch. Is it doing what you want ? If not, then describe what it does and what you want it to do

What action do you want to take after the "certain number of steps" ? I ask, because there is no such action in your sketch