I want to print the time on the serial monitor at the start and end of a signal (Help)

What is the difference between them.
The problem here is that the iterative loop is in conflict with the void loop function. Because instead of working only once and checking the condition, it continues to work every time.