HTML Server, client.stop

I am relatively new to programming the arduino. I am currently working with turning the arduino into a webserver. In the process I have been studying the example code entitled Ethernet Shield WebServer, found here https://docs.arduino.cc/tutorials/ethernet-shield-rev2/WebServer.

It looks like every time the arduino loops through the code the client is disconnect, ie client.stop(). When I checked the serial output on my board the client would be connected and disconnected as my laptop was acting as the client, ie displaying the webpage.

I am I getting this right? If so why does the client need to constantly connected and disconnect?

the client.stop() is sent when you exit from the while (client.connected()), that is when you have received the full request and provided the answer

Can I "hold off" on the client.stop()? Tie it to when the client disconnects?

that's what happens. you send the stop only when client.connected() said false

    while (client.connected()) {
      // handle the request 
    }
    // now client is no longer connected
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();

because it is much simpler than managing connections which are keep alive.

If I want to do other things with my board then just be a webserver, control lights, motors, etc; can I replace the while loop with if statements?

once you've dealt with a client request you can do other stuff, sure