Serial.available acting funny

Couple of remarks, hope they can help.

First, the line ' //}' seems weird, with the comment marks it does NOT compile. Taking out the '//' compiles ok.

Next, does it actually print the "length" string? If x is not inside your range, nothing is done, whatever you receive.

Then, the line 'float distance = analogRead(1);', again hmm, analogRead returns a int, not a float. Not critical, but not clean.

But, most critical, you are not looping yourself, but using the Arduino background code to repeatedly call loop(). This means you are not in full control over what the system is doing. Even in the Arduino the microcontroller 'rule' the main function never exits is still a good one to follow.

Now, i am not sure, but it looks like the serial buffer is reset upon entering loop().

If i place the main block in a while(true) { .. } loop, it seems to work; at least it sees the incoming data etc.

Oh, and finally, the lines
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
make no sense, inComingByte is initialise to 0 and never set.

HTH,
Guido