while loop question

while (numChar--) {
buffer[index++] = Serial.read();

The code above is a snippet from the ASKManual Version 5.

The author explains it as such: "The condition it is checking is simply numChar, so in other words it is checking that the value stored in the integer numChar is not zero"

I do not see any where that the condition of "not zero" is being checked. I see only the decrement. Shouldn't there be something like !=0. ??

I am a newbie so sorry if this is a dumb question

The value of numchar is tested for true/false [u]before[/u] the (post-)decrement takes place. It isn't necessary to assign the value of an expression in order to examine it.

In C or C++ True is any Non-Zero Value like .... -3,-2,-1,1,2,3.... False is Zero

syntax: while( expression) statement;


while( expression) { statements }

expression can be evalueted as Zero or Non-Zero

if the expression is Non-Zero then statement or statements will be executed.

i.e. while(numChar--) can be treated as

while(numChar !=0) {

numChar--; }

thanks all, this makes sense now