Lecture 3
Lecture 3
Mumtahina Ahmed
Lecture 03
C Flow Control
Program in CValues and VariablesExpressionsStandard Input/Output
C break
The break statement ends the loop immediately when it is encountered. Its syntax is:
The break statement is almost always used with if...else statement inside the loop.
Program in CValues and VariablesExpressionsStandard Input/Output
Output
C continue
The continue statement skips the current iteration of the loop and continues with the
next iteration. Its syntax is:
The continue statement is almost always used with the if...else statement.
Program in CValues and VariablesExpressionsStandard Input/Output
Output
C goto Statement
C goto statement
The goto statement allows us to transfer control of the program to the specified label.
The label is an identifier. When the goto statement is encountered, the control of the
program jumps to label: and starts executing the code.
Program in CValues and VariablesExpressionsStandard Input/Output
C switch Statement
The switch statement allows us to execute one code block among many alternatives.
You can do the same thing with the if...else..if ladder. However, the syntax of
the switch statement is much easier to read and write.
Program in CValues and VariablesExpressionsStandard Input/Output
Notes:
1. If we do not use the break statement, all statements after the matching
label are also executed.
2. The default clause inside the switch statement is optional.
Program in CValues and VariablesExpressionsStandard Input/Output
Notes:
1. If we do not use the break statement, all statements after the matching
label are also executed.
2. The default clause inside the switch statement is optional.
Program in CValues and VariablesExpressionsStandard Input/Output
Thank You!