Enhanced for loop usage

1、 Enhanced for loop

Enhance the function of the for loop: simplify the writing format of the iterator. (Note: enhancing the bottom layer of the for loop still uses iterator traversal.) Scope of application of enhanced for loop: if it is an object or array object that implements the iteratable interface, you can use enhanced for loop. Disadvantages of enhancing the for loop: the effect of enhancing the for loop and iterator traversal is the same, that is, enhancing the internal of the for loop is implemented by calling iterator, but there are some disadvantages of enhancing the for loop, such as unable to dynamically delete the set content in the enhanced loop, unable to obtain subscripts, etc.

2、 Enhanced for loop format:

For (data type variable name: traversal target) {/ / data type variable name: declare a variable to receive the element traversed by the traversal target

}

3、 Considerations for enhancing the for loop:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>