user21576: not sure what is going wrong in the code below, but it's a simplified code of a larger piece I'm trying to debug. I notice that the code seems to skip to the else statement even though the if statement is valid.
Potential is set to analogRead(A0)
while (potential < 1023) {
Serial.println(analogRead(A0));
if (potential < 1023) {
  if (potential > 200) {
    Serial.println("cool");
  } else {
    Serial.println("low");
    lcd.print("hello");
    delay(1000);
  }
}

Results in serial monitor show 
235
low
324
low

I've also tried if (potential < 1023 && potential > 200) and if ((potential < 1023) && (potential >200)) to no avail.
Can anyone help, let me know what's going wrong or suggest a fix to this?

user8033: I'm not sure what you're trying to achieve with that while.
But this will result in none of your other code being executed until potential is above 1022, which sound rather weird. (Unless it's for some kind of safety mechanism).
The problem is that you do send the new value over serial.
But you do not assign that new value to the variable 'potential'.
Basically, you see something completely different as what is actually happening.
You should do Serial.println(potential); to be sure that you print the value of 'potential'.
And you should assign the analogRead(A0); to your variable potential.
I've also taken away the while since I think it would be misplaced. And I worked around it, so it doesn't block your complete sketch.
void loop() {
  potential = analogRead(A0));
  Serial.println(potential);

  if (potential < 1023) {
    if (potential > 200) {
      Serial.println("cool");
    } else {
      Serial.println("low");
      lcd.print("hello");
      delay(1000);
    }
  }else{
    //Code that won't run if potential < 1023
  }

  //Other code that can run "simultaniously".
}


21576: <p>not sure what is going wrong in the code below, but it's a simplified code of a larger piece I'm trying to debug. I notice that the code seems to skip to the else statement even though the if statement is valid.
Potential is set to analogRead(A0)</p>

<pre><code>while (potential &lt; 1023) {
Serial.println(analogRead(A0));
if (potential &lt; 1023) {
  if (potential &gt; 200) {
    Serial.println("cool");
  } else {
    Serial.println("low");
    lcd.print("hello");
    delay(1000);
  }
}
</code></pre>

<p>Results in serial monitor show </p>

<pre><code>235
low
324
low
</code></pre>

<p>I've also tried if (potential &lt; 1023 &amp;&amp; potential > 200) and if ((potential &lt; 1023) &amp;&amp; (potential >200)) to no avail.</p>

<p>Can anyone help, let me know what's going wrong or suggest a fix to this?</p>
 8033: <p>I'm not sure what you're trying to achieve with that <code>while</code>.
But this will result in none of your other code being executed until potential is above 1022, which sound rather weird. (Unless it's for some kind of safety mechanism).</p>

<p>The problem is that you do send the new value over serial.
But you do not assign that new value to the variable 'potential'.</p>

<p>Basically, you see something completely different as what is actually happening.
You should do <code>Serial.println(potential);</code> to be sure that you print the value of 'potential'.</p>

<p>And you should assign the <code>analogRead(A0);</code> to your variable <code>potential</code>.</p>

<p>I've also taken away the <code>while</code> since I think it would be misplaced. And I worked around it, so it doesn't block your complete sketch.</p>

<pre><code>void loop() {
  potential = analogRead(A0));
  Serial.println(potential);

  if (potential &lt; 1023) {
    if (potential &gt; 200) {
      Serial.println("cool");
    } else {
      Serial.println("low");
      lcd.print("hello");
      delay(1000);
    }
  }else{
    //Code that won't run if potential &lt; 1023
  }

  //Other code that can run "simultaniously".
}
</code></pre>
