



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




if (condition) { statement(s); } else if (condition) { statement(s); } else { statement(s); }
if ( TRUE ) { /* Execute these stmts if TRUE / } else { / Execute these stmts if FALSE */ }
switch (
SWITCH NOTES: Notice, no {} blocks within each case. Notice the colon for each case and value. The “condition” of a switch statement is a value. The default case is optional, but it is wise to include it as it handles any unexpected cases. Chooses first match…
#include <stdio.h> int main() { int age; / Need a variable... / printf( "Please enter your age" ); / Asks for age / scanf( "%d", &age ); / The input is put in age / if ( age < 100 ) { / If the age is less than 100 / printf ("You are pretty young!\n" ); } / Just to show you it works... / else if ( age == 100 ) { / use else to show an example / printf( "You are old\n" ); } / how rude! / else { printf( "You are really old\n" ); } / do this if no other block exec / return 0; }
NOTE: You do not have to use {} if only one statement in the block. None of the above brackets in the IF structure are necessary! Check out where the semi-colon goes (and where it doesn’t).