How to stop a 60 second timer when a certain event takes place ?

For a project I have a timer which increases x by every second, from 1 to 60. This continues until either the 60 seconds is reached or the PIR reading is high. I have tried a for loop inside a do while loop. Like below:

do {
      for (x = 1; x <= 60;) {
        delay(1000);
        x++;
        Serial.println(x);
       
      }

    } while (pirStat == HIGH);

However, this does not work. The aim of this is to create a 60 second timer, which carries on until either the 60 seconds is reached or motion is detected. The time between the start and end should be recorded. I also need to store the variable between the start and end temporarily

Use millis() for timing. Don’t use delay().
Check the blink without delay example in the IDE.

It’s very easy to then have a Boolean flag as to if you need to check the timer or not. If the motion is detected you just clear the flag so you’re no longer checking the timer.

a for loop runs through until the condition that is defined inthe head of the for-loop is true
this condition in your for-loop is x<= 60

the loop counts up variable x and stays inside this part of your code

for (x = 1; x <= 60;) {[color=#222222][/color]
        delay(1000);[color=#222222][/color]
        x++;[color=#222222][/color]
        Serial.println(x);

only after reaching x = 60 your condition

while (pirStat == HIGH)

is checked again.
That’s the reason why it does not work this way.

You have two things that shall stop the count-down
60 seconds have passed by
pitstat == HIGH

It will work if have one while-loop that checks for two things
are 60 seconds over?
is pitstat == HIGH?

delay(1000) blocks the whole microcontroller for 1000 milliseconds = 1 second.
Nothing else but delaying is done.

This means whenever pirstat goes HIGH if your code includes a delay the oirstat == HIGH gets only detected if the last delay is over. which means there is a delay in stopping the counter from 0,1 to 0,999 seconds.
That is the reason why you should use millis() instead of delay().

So re-think the conditions and write a new version
best regards Stefan
any newbee can apply the most professional habit from the first line of code they write on their own:
add only ONE thing at a time. Test/debug that ONE thing until that ONE thing works reliable - repeat.
The sad thing is: only the REAL professionals write code this way.