当前位置:网站首页>Return in foreach and break in for
Return in foreach and break in for
2022-06-11 07:50:00 【Jingling cat】
difference

to want to End for loop , Use return

Only Zhao Liu hasn't been printed out , Subsequent array elements are still executed .
foreach in
keyword "return", The effect of execution is equivalent to ordinary for Keywords in the loop continue
return It doesn't mean the original return The meaning of representation
"break" or "continue" Is not allowed to use
Ordinary for In circulation
Want to end early ( End ) The circular body uses "break";
End the cycle , For the next round of recycling "continue";
Use "return", Not only force the end for The loop body , It also ends the entire method containing the loop body ahead of time
principle

forEach(), In the final analysis, it is a method , and Not a loop , End the execution of a method yes return
Common operations
for In circulation break Terminate the current loop , Continue with the next code

for In circulation return Terminate the current loop , The next code is not executed , Method returns

In operation , There are often many unexpected situations that cause code to terminate prematurely
such as : Null pointer exception , So you can terminate by throwing a false exception forEach

This way is not friendly , You can pack it again 
边栏推荐
- Switch statement
- [atcoder2000] leftmost ball (dp+ combination number)
- [atcoder1981] short diameter (graph theory thinking)
- 模线性方程组(中国剩余定理+通用解法)
- C language to achieve minesweeping games
- mpi
- 134. 加油站
- C language - growth diary-04- preliminary exploration of local variables (local variables)
- Pycrypto packaging error
- Implementation of queue (C language)
猜你喜欢

A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language

Lesson 1 about Xiaobai's C language

Zero foundation self-study SQL course | outer join external connection

2021-11-05 definition of cache
![[IOT] project management: how to build a better cross functional team?](/img/df/28dbf0f7ba75d1bb3469cc15e70538.png)
[IOT] project management: how to build a better cross functional team?

空间几何

C wechat upload form data

Flask页面的分页

Detailed explanation of character function and string function (including simulation implementation)

Getting started with bladed tutorial (video)
随机推荐
排序——交换排序
[atcoder1998] stamp Rally
Paging of the flask page
2021-11-05 definition of cache
C wechat upload form data
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]
[untitled] Weng_ C lesson 1
Summary of evaluation index knowledge points in target detection: summary of IOU cross overlap unit and map/ap/tp/fp/np
Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel
自定义ViewGroup的知识点总结-持续更新
如何准备PMP新版大纲考试?
Simple configuration of vscade
记一次忽略@SuppressLint(“NewApi“)提示引发的血案
Classes and objects (medium)
Pycrypto packaging error
C language lesson 2
20200802 T3 I always like [generating function exclusion, Lagrangian inversion]
Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
[atcoder2306] rearranging (topology)
C- print 99 multiplication table