Go Down

Topic: Function of "for(;;);" in attached code? (Read 747 times) previous topic - next topic

zoomkat

What is the function of for(;;); near the bottom of the below code? I think I saw what it does in the past, but can't recall it now.

Code: [Select]

//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor and push reset button to
//see what the arduino receives

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 };
byte server[] = { 208, 104, 2, 86 }; // zoomkat

Client client(server, 80);

void setup()
{
 Ethernet.begin(mac, ip);
 Serial.begin(9600);
 Serial.println("starting simple arduino client test");
 Serial.println();

 delay(1000);

 Serial.println("connecting...");

 if (client.connect()) {
   Serial.println("connected");
   client.println("GET /~shb/arduino.txt HTTP/1.0");
   client.println();
 } else {
   Serial.println("connection failed");
 }
}

void loop()
{
 if (client.available()) {
   char c = client.read();
   Serial.print(c);
 }

 if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
   client.stop();
   for(;;);
 }
}
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

AWOL

#1
Nov 25, 2010, 06:31 pm Last Edit: Nov 25, 2010, 06:36 pm by AWOL Reason: 1
Code: [Select]
#define EVER (;;)

for EVER


I confess I've never quite understood why an empty condition should always evaluate as TRUE.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Quote
I confess I've never quite understood why an empty condition should always evaluate as TRUE.

The middle part of the for loop is a while condition. While not false, do something. An empty expression is not false. There is only one other possibility.

robtillaart

Quote
I confess I've never quite understood why an empty condition should always evaluate as TRUE.

Tech answer: it is by definition as far as I know
Spiritual answer: There is Truth in Emptyness  - buddhism? :)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up