From C to C++
- slide 21 : 29
Control structures
The control structures in C are well-known - and almost identical - to control structures in other languages in the C family
Selection
if
conditional and
if-else
switch
- with the
break
issue!
Iteration
while
and
do-while
for
C++: Can declare local variables (of one type) in the initialization part
C: This is not possible in ANSI C - C89
Ohter control mechanisms in C
goto
,
break
,
continue
Blocks:
{...}
A program with a for loop in C.
Program output.
Illustration of local variables in a for loop in C++.
Program output.