Computer Skills & Programming II Dr. Shayma Akram Yousif
12
Note:
You can write any C++ program without the use of goto statement and is generally
considered a good idea not to use it.
Reason to Avoid goto Statement
The goto statement gives the power to jump to any part of a program but,
makes the logic of the program complex and tangled.
In modern programming, the goto statement is considered a harmful
construct and a bad programming practice.
The goto statement can be replaced in most of C++ program with the use
of break and continue statements.
C++ return statement
The return statement returns the flow of the execution to the function from where
it is called. This statement does not mandatorily need any conditional statements. As
soon as the statement is executed, the flow of the program stops immediately and
return the control from where it was called. The return statement may or may not
return anything for a void function, but for a non-void function, a return value is
must be returned.
Syntax:
return[expression];