Hello and
Asalam o Alikum. I hope you all are fine by the grace of Allah Almighty.
Today I am
here with a program that explains the purpose of “break” statement.
"Break" statement
The “break”
statement is used in the body of the loop to exit from the loop. When this
statement is used in the body of the loop, the remaining iterations are skipped
and the statement outside the body of the loop is executed.
Below is the source code of an example of "break" statement.
Source code
Output
Explanation
The above
program contains “break” statement in the body of the loop. According to the
condition given in the loop, it should display the statement,” Welcome to my
blog” for 5 times but due to “break” statement, it will display this statement
for only one time. The control will skip the remaining iterations and comes out
of the body of the loop. It will then display, “Good bye”.
No comments:
Post a Comment