Zero can be false because most CPU's have a ZERO flag that can be used to branch. It saves a compare operation.
Lets see why.
Some psuedocode, as the audience probably don't read assembly
c- source simple loop calls wibble 10 times
for (int foo =10; foo>0; foo-- ) /* down count loop is shorter */ { wibble(); } some pretend assembly for that
0x1000 ld a 0x0a 'foo=10 0x1002 call 0x1234 'call wibble() 0x1005 dec a 'foo-- 0x1006 jrnz -0x06 'jump back to 0x1000 if not zero 0x1008 c- source another simple loop calls wibble 10 times
for (int foo =0; foo<10; foo-- ) /* up count loop is longer */ { wibble(); } some pretend assembly for this case
0x1000 ld a 0x00 'foo=0 0x1002 call 0x1234 'call wibble() 0x1005 dec a 'foo-- 0x1006 cmp 0x0a 'compare foo to 10 ( like a subtract but we throw the result away) 0x1008 jrns -0x08 'jump back to 0x1000 if compare was negative 0x100a some more c source
int foo=10; if ( foo ) wibble() and the assembly
0x1000 ld a 0x10 0x1002 jz 0x3 0x1004 call 0x1234 0x1007 see how short that is ?
some more c source
int foo=10; if ( foo==0 ) wibble() and the assembly (lets assume a marginally smart compiler that can replace ==0 with no compare)
0x1000 ld a 0x10 0x1002 jz 0x3 0x1004 call 0x1234 0x1007 Now lets try a convention of true=1
some more c source #define TRUE 1 int foo=TRUE; if ( foo==TRUE ) wibble()
and the assembly
0x1000 ld a 0x1 0x1002 cmp a 0x01 0x1004 jz 0x3 0x1006 call 0x1234 0x1009 see how short the case with nonzero true is ?
Really early CPU's had small sets of flags attached to the Accumulator.
To check if a>b or a=b generally takes a compare instruction.
- Unless B is either ZERO - in which case the ZERO flag is set Implemented as a simple logical NOR or all bits in the Accumulator.
- Or NEGATIVE in which just use the "sign bit" i.e. the most significant bit of the Accumulator if you are using two's complement arithmetic. (Mostly we do)
Lets restate this. On some older CPU's you did not have to use a compare instruction for accumulator equal to ZERO, or accumulator less than zero.
Now do you see why zero might be false ?
Please note this is psuedo-code and no real instruction set looks quite like this. If you know assembly you know I'm simplifying things a lot here. If you know anything about compiler design, you didn't need to read this answer. Anyone who knows anything about loop unrolling or branch prediction, the advanced class is down the hall in room 203.