EthernetClient: while (!client) = infinite loop???

I tried the EthernetClient example:

It seems to end up to infinite loop at while(!client).
Serial.print (client) clearly prints 0 until client.connect has succeeded.

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte server[] =  { 173,194,40,228 }; // { 64, 233, 187, 99 }; // Google

EthernetClient client;

void setup()
  Ethernet.begin(mac, ip);


    ; // wait until there is a client connected to proceed
  if (client.connect(server, 80)) {
    client.println("GET /search?q=arduino HTTP/1.0");
  } else {
    Serial.println("connection failed");

void loop()
  if (client.available()) {
    char c =;

  if (!client.connected()) {

The reason why I popped in is that occasionally the first connect attempt to my server fails (for no visible reason) and the second attempt succeeds. I was hoping that this while-loop would resolve this, but… However that is another story.

That article is wrong, 'if(client)' checks the client port is not zero. As the example has not used client, it will always be zero. I would simply remove the whole loop.

For the best Ethernet experience, I put a long delay before calling begin, DHCP was almost instant, whereas without a delay could take ages.