What is the difference between continue, break, and return?

In the loop structure, when the loop conditions are not met or the number of loops reaches the requirement, the loop will end normally. However, sometimes it may be necessary to terminate the loop prematurely when a certain condition occurs in the process of the loop , which requires the use of the following keywords:

  • continue: refers to jumping out of the current loop and continuing to the next loop.
  • break: refers to jumping out of the entire loop body and continuing to execute the statement below the loop.
  • return is used to jump out of the method and end the operation of the method. There are generally two uses for return:
  • return;: Use return directly to end method execution, used for methods without return value function
  • return value;: return a specific value, used for methods with return value functions

 What is the return value of a method and what is its function?

The return value of a method refers to the result of the execution of the code in a certain method body we obtained! (The premise is that the method may produce results). The function of the return value: Receive the result so that it can be used for other operations!

 

Guess you like

Origin blog.csdn.net/weixin_51980491/article/details/112738828