ideal for situations where you always want the loop to iterate at least once.
3.
The for loop:
As we have seen, the
for loop
is a pretest loop that has inbuilt expressions for
initializing, testing, and updating. These expressions make it very convenient to use a loop
control variable as a counter.
The for loop is ideal in situations where the exact number of
iterations is known.
The return Statement
A return statement is used only in methods (functions in C and member-functions in C++ are known as
methods in Java). It terminates the method’s execution by transferring control to the calling method.
Thus, if a method has to return a value, you may write:
Do'stlaringiz bilan baham: |