what is ISR

hi guys, I am a bit confused about ISR function I read a lot but I still don't understand exactly what is the function of it for an example this code is it for generating a wave only?? and how does it work ??

ISR(TIMER2_COMPA_vect) { //timer2 interrupt  toggles pin 8
  //generates pulse wave
  if (toggle0) {
    digitalWrite(myOutputPin2, HIGH);
    toggle0 = 0;
  }
  else {
    digitalWrite(myOutputPin2, LOW);
    toggle0 = 1;
  }

ISR is simply Interrupt Service Routine.
When an interrupt occurs it is the function that is called via a fixed vector.
In your case,it is called by a the Timer2 comparison interrupt.

TheMemberFormerlyKnownAsAWOL:
ISR is simply Interrupt Service Routine.
When an interrupt occurs it is the function that is called via a fixed vector.
In your case,it is called by a the Timer2 comparison interrupt.

so that's mean the interrupt is like infinite loop it occurs when the condition happens

No, most definitely not an infinite loop.

ok, thanks a lot

Very simple concept.

Processor executes program.
An interrupt occurs.
Assuming interrupts are enabled, before the next machine instruction executes, the program counter is pushed onto the stack, and then the program counter is loaded with a value based on which interrupt has occured (the vector)
The code continues to run until a “return from interrupt” instruction is encountered, when the program counter is popped off the stack, and the original main program continues where it left off.

This is all well-documented.

my guessing: a description like

the program counter is pushed onto the stack,

is too abstract for newbees

https://microcontrollerslab.com/use-arduino-interrupts-examples/

and maybe this one

https://www.tutorialspoint.com/arduino/arduino_interrupts.htm

there is more than one way to skin a cat:

the cat was climbing in
the cat got interrupted
the cat performed the "get out of this" ISR
when the interrupt was handled
the cat returned to climbing in

  attachInterrupt(digitalPinToInterrupt(2), pps_isr, RISING);                   // enable GPS 1pps hardware interrupt input on pin 2
  attachInterrupt(digitalPinToInterrupt(3), sqw_isr, RISING);                   // enable RTC 1pps hardware interrupt input on pin 3