17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

switch<br />

Switch is also a special multi-way decision maker.<br />

The syntax is<br />

switch (expr) {<br />

case const1: stmt sequence;<br />

break;<br />

...<br />

[default:stmt]<br />

}<br />

This tests whether the expression matches one of the constant values and branches<br />

accordingly.<br />

If none of the cases are satisfied the default case is executed. The break causes an immediate<br />

exit, otherwise control falls through to the next case.<br />

Example:<br />

switch (cmd) {<br />

case 0:printf("cmd 0");<br />

break;<br />

case 1:printf("cmd 1");<br />

break;<br />

default:printf("bad cmd");<br />

break; }<br />

Also See: Statements<br />

return<br />

return<br />

A return statement allows an immediate exit from a switch or a loop or function and also<br />

returns a value.<br />

The syntax is:<br />

return(expr);<br />

Example:<br />

return (5);<br />

Also See: Statements<br />

18

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

Saved successfully!

Ooh no, something went wrong!