If your board is DOIT ESP32_DEVKIT_V1, you have to select correspondingly. Selecting ESP32_DEV, etc. will cause the board to reboot like that.
You can also have to add delay(1) in the loop(), such as
delay(1)
void loop() { ... delay(1); }