Lecture 1 - Slide 26 : 34
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 (not possile in ANSI C)
C++: Range-
for
(called
foreach
in similar languages)
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.