do-while Update variable from within the loop?

Hi I'm having trouble understanding one aspect of do while loop.

code snippet below;

void loop() { int x=analogRead(sensePin);

do {digitalWrite(boardLED,HIGH); delay(50); } while (analogRead(sensePin)>=500);

This works as I would expect. Below 500 and it exits the loop. Above 500 and it stays in the loop - etc.

BUT

void loop() { int x=analogRead(sensePin);

do {digitalWrite(boardLED,HIGH); delay(50); x=analogRead(sensePin); } while (x>=500);

This doesn't work as I would expect. If the value is above 500 it stays in the loop - all good. But when I change the value to below 500 it stays stuck in the loop. Shouldn't the "x=analogRead(sensePin);" inside the loop, write the value to "int x" at the start of the void loop and therefore when the while loop checks condition it will be lower than 500 and exit the loop(cause it doesn't)?

Thanks Very Much John

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” button above the posting area (It looks like a scroll with < > inside it).

Can you post all your code please? This looks like a snippet.

http://snippets-r-us.com/

Something I can compile and test.

Hi Thanks Nick for your super speedy response! I will put code in correct place next time. As soon as I posted this I found my error. I was about to delete the post.

In the actual code I had copy and pasted the "x=" in the loop as "int x=" So I guess I had declared a different variable. So when I correct it to - just "x=" then it works as I would expect. Thanks again. John

Ah yes, I was looking for the "int" but it did not appear in your post.

In the actual code I had ...

Yes, the "actual code" is always helpful when answering questions.