17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

if<br />

if-else<br />

The if-else statement is used to make decisions.<br />

The syntax is:<br />

if (expr)<br />

stmt-1;<br />

[else<br />

stmt-2;]<br />

The expression is evaluated; if it is true stmt-1 is done. If it is false then stmt-2 is done.<br />

else-if<br />

This is used to make multi-way decisions.<br />

The syntax is:<br />

if (expr)<br />

stmt;<br />

[else if (expr)<br />

stmt;]<br />

...<br />

[else<br />

stmt;]<br />

The expressions are evaluated in order; if any expression is true, the statement associated with<br />

it is executed and it terminates the chain. If none of the conditions are satisfied the last else part<br />

is executed.<br />

Example:<br />

if (x==25)<br />

x=1;<br />

else<br />

x=x+1;<br />

Also See: Statements<br />

while<br />

While is used as a loop/iteration statement.<br />

The syntax is:<br />

while (expr)<br />

statement<br />

16

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!