Serial monitor resets arduino everytime?

Everytime, when I open the serial monitor in the arduino ide, it seems, the arduino starts to work from the beginning of the code. How does this happen?

If I just want the pc communicate with the arduino from time to time, may I avoid this?

That is the intended behaviour. When the PC program opens the serial port the Arduino resets.

If you want to start a serial connection from time to time without disturbing the Arduino the simplest way is probably to use a USB-TTL cable connected directly to Rx Tx and GND.

There are mechanisms for disabling the auto-reset feature but they can get in the way of uploading programs.

...R

If you want the PC to communicate with the Arduino from time to time, you can use a dedicated terminal program. Saves you from having to open the IDE first as well.

Some offer the option to suppress DTR/RTS when opening the serial port. At the windows side of the world, RealTerm is one of them.

Alternatively, you can write your own.

// Edit
Be aware that only one application can have the serial port open at a time. So any terminal program can interfere when you want to upload a new code; that is the only benefit of using Serial Monitor as the IDE handles it all.