CS 24000 Study Guide - Midterm Guide: Switch Statement

15 views2 pages

For unlimited access to Study Guides, a Grade+ subscription is required.

CS240&Lecture&6&Notes&review&2&
For$statement$
“for”&statement&is&typically&used&in&situation&where&you&know&in&advance&the&
number&of&iterations&
Syntax:&&
for(expression1; expression2; expression3){
....
}
Example:&
//Assuming the variable i has been declared above.
for(i = 0; i < 10; i++){
....... // code to be executed goes here
// this specific for statement will
// loop until !(i < 10) for a total
// of 10 iterations
}
&
for$statement$
However&you&could&use&the&for&statement&where&a&while&statement&is&also&
used&
Example:&
expr1;
while(expr2){
// body of statement to be executed
expr3;
}
//expr1 and expr3 are usually 'coma expressions'
expr1 expr2 expr3
for( i = 0, j = 0; i < 10; i++ ){!
// body of statement to be executed
}
&
switch$statement$
&&switch(expr) {!
case const1: .... break;
case const2: .... break;
default: .... break;
!}&
expr&is&evaluated&and&converted&to&an&int&
if&….expr….is&equal&to&any&of&const&values&that&block&of&code&is&executed&
default&is&evaluated&I&expr&does&not&match&any&of&the&case&consts.&
&
Forever$loops$(infinite$loops)$
while(1){!
// body runs forever
}
for(;;){!
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class