Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Switch-Computer Fundamentals-Lecture Slides, Slides of Computer Fundamentals

The course covers important and advance elements of C and C plus plus programming language. This course provides the student with the skills required to design, code, and test and execute programs of simple to intermediate complexity. It includes: Switch, Multiple-Selection, Statement, Format, Series, Case, Labels, Default, Flowchart, While, Repetition

Typology: Slides

2011/2012

Uploaded on 07/31/2012

karthik
karthik 🇮🇳

4.6

(16)

95 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
.
19
4.7 The switch Multiple-Selection Statement
switch
Useful when a variable or expression is tested for all the
values it can assume and different actions are taken
Format
Series of case labels and an optional default case
switch ( value ){
case '1':
actions
case '2':
actions
default:
actions
}
break; exits from statement
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Switch-Computer Fundamentals-Lecture Slides and more Slides Computer Fundamentals in PDF only on Docsity!

4.7 The switch Multiple-Selection Statement

• switch

– Useful when a variable or expression is tested for all the

values it can assume and different actions are taken

• Format

– Series of case labels and an optional default case

switch ( value ){

case '1':

actions

case '2':

actions

default:

actions

– break; exits from statement

4.7 The switch Multiple-Selection Statement

• Flowchart of the switch statement

true

false

case a case a action(s) break

case b case b action(s) break

false

false

case z case z action(s) break

true

true

default action(s)

OutlineOutline

fig04_07.c (Part 2 of

OutlineOutline

fig04_07.c (Part 3 of

4.8 The do … while Repetition Statement

• The do…while repetition statement

– Similar to the while structure

– Condition for repetition tested after the body of the loop is

performed

• All actions are performed at least once

– Format:

do {

statement ;

} while ( condition );

4.8 The do … while Repetition Statement

• Example (letting counter = 1):

do {

printf( "%d ", counter );

} while (++counter <= 10);

– Prints the integers from 1 to 10

OutlineOutline

fig04_09.c

Program Output

4.9 The break and continue Statements

• break

– Causes immediate exit from a while, for, do…while or

switch statement

– Program execution continues with the first statement after

the structure

– Common uses of the break statement

• Escape early from a loop

• Skip the remainder of a switch statement

4.9 The break and continue Statements

• continue

– Skips the remaining statements in the body of a while, for

or do…while statement

• Proceeds with the next iteration of the loop

– while and do…while

• Loop-continuation test is evaluated immediately after the

continue statement is executed

– for

• Increment expression is executed, then the loop-continuation

test is evaluated

OutlineOutline

fig04_12.c

Program Output

Used continue to skip printing the value 5