Title: More Program Flow
1More Program Flow
2goto Loops
void main() int counter 0 myloop cout ltlt
"counter " ltlt counter ltlt endl counter if
(counter lt 5) goto myloop cout ltlt "Complete.
Counter " ltlt counter ltlt endl
3while Loops
void main() int counter 0 while (counter lt
5) cout ltlt "counter " ltlt counter ltlt
endl counter cout ltlt "Complete.
Counter " ltlt counter ltlt endl
4do while Loops
void main() int counter 0 do cout ltlt
"counter " ltlt counter ltlt endl counter w
hile (counter lt 5) cout ltlt "Complete. Counter
" ltlt counter ltlt endl
5for Loops
void main() int counter for (counter 0
counter lt 5 counter) cout ltlt "counter "
ltlt counter ltlt endl cout ltlt "Complete.
Counter " ltlt counter ltlt endl
6break
void main() int counter for (counter 0
counter lt 9 counter) if (counter gt
5) break cout ltlt "counter " ltlt counter ltlt
endl cout ltlt "Complete. Counter " ltlt
counter ltlt endl
7continue
void main() int counter for (counter 0
counter lt 9 counter) if ((counter 2)
0) continue cout ltlt "counter " ltlt counter
ltlt endl cout ltlt "Complete. Counter " ltlt
counter ltlt endl
8Fall Through switch
void main() int MyNumber cout ltlt "Enter a
number from 1 to 5 " cin gtgt MyNumber switch
(MyNumber) case 5 cout ltlt "5 " case 4
cout ltlt "4 " case 3 cout ltlt "3 " case 2
cout ltlt "2 " case 1 cout ltlt "1 " cout ltlt
endl ltlt endl
9break from switch with default
void main() int MyNumber switch
(MyNumber) case 1 cout ltlt "You
selected 1" ltlt endl break case 2
cout ltlt "You selected 2" ltlt endl break
case 3 cout ltlt "You selected 3" ltlt endl
break case 4 cout ltlt "You selected 4" ltlt
endl break case 5 cout ltlt "You
selected 5" ltlt endl break default
cout ltlt"The number you selected "
ltltMyNumber cout ltlt ", is out of
range." ltlt endl