Syntax Structures Flashcards
An if-statement is your basic logic branching control
i f (TEST) { CODE; } e l s e i f (TEST) { CODE; } e l s e { CODE; }
A switch-statement is like an if-statement but works on simple integer constants
s w i t c h (OPERAND) { c a s e CONSTANT: CODE; break ; d e f a u l t : CODE; }
A while-loop is your most basic loop
w h i l e (TEST) {
CODE;
}
You can also use continue to cause it to loop. Call this form while-continue-loop for now
w h i l e (TEST) { i f (OTHER_TEST) { c o n t i n u e ; } CODE; }
You can also use break to exit a loop. Call this form while-break-loop
w h i l e (TEST) { i f (OTHER_TEST) { break ; } CODE; }
The do-while-loop is an inverted version of a while-loop that runs the code then tests to see
if it should run again
do {
CODE;
} w h i l e (TEST ) ;
The for-loop does a controlled counted loop through a (hopefully) fixed number of iterations
using a counter
f o r ( INIT ; TEST ; POST) {
CODE;
}
An enum creates a set of integer constants
enum { CONST1, CONST2, CONST3 } NAME;
A goto will jumpt to a label, and is only used in a few useful situations like error detection and
exiting
i f (ERROR_TEST) { goto f a i l ; } f a i l : CODE;
A function is defined this way
TYPE NAME(ARG1, ARG2, . . ) {
CODE;
r e t u r n VALUE;
}
A typedef defines a new type
t y p e d e f DEFINITION IDENTIFIER ;
(A typedef defines a new type) A more concrete form of this is
t y p e d e f unsigned char byte ;