Getting Started

(lily) #1

Chapter 5: C Control Flow


rSecondCount < 2200)

s that while QuarterSecondCount is less than 2200, set
uarterSecondCount to 0. So each time the interrupt incremented

nt of time locating, you
less or both.
rtuna ly, I am my o n bos so I’ d and careless

has a non-zero result (it is true), then we do statement 1, if the

lated

Which is two statements, the first waits while an interrupt increments
QuarterSecondCount in the background, and once that is finished the
QuarterSecondCount is set to zero. What the compiler saw was:


while(Quarte
QuarterSecondCount = 0;


because the compiler doesn’t see the comments – the \17600;. See the problem
yet?


Well how about he equivalent statement:


while(QuarterSecondCount < 2200) QuarterSecondCount = 0;


The compiler also doesn’t know about the line break, all it sees is the last
statement, which say
Q
QuarterSecondCount, this statement set it back to zero.


This is the kind of bug, that after spending X amou
carefully hide it from your boss lest she think you are stupid or care
Fo te w s, ve learned to live with my stupi
employee. (I fired myself once, but that just didn’t work out.)


If-Else and Else-If


We can make d cision using e if-ee s th lse statement:


if (expression)
statement1
else
statement2


If the expression
e e) we do statement 2. We can make a list of
decisions using else if:


xpression has a 0 result (it is fals
re

Free download pdf