Help with some programming!!

Ok. Actually I have made some changes to my programme (have attached it). Now the servo should rotate when setCursor is 5.

I have added the serial codes to the servo () function as well and this a reduced version of what I got as output:

setCounter = 0
Starting loop()
setCounter = 0
Starting loop()
setCounter = 1
Starting loop()
setCounter = 1
Starting loop()
setCounter = 2
Starting loop()
setCounter = 2
Starting loop()
setCounter = 3
Starting loop()
setCounter = 3
Starting loop()
setCounter = 4
Starting loop()
setCounter = 4
Starting loop()
setCounter = 5
Starting loop()
setCounter = 5

The setCounter = 5 appears when the servo rotates, and I got this when it rotates at the required timing

But when the servo rotated randomly at unwanted timing, the output was still showing as setCounter = 0

To be more specific of my problem, the servo motor only rotates randomly when I have uploaded the programme onto the arduino and till the point when the cursor has been set to 5. After which, it rotates as needed

fypprogram2.txt (14.3 KB)