foreach-loops

Learn how to use foreach-loops to loop over list-like structures.

Python for-loops loop over sequences; a list is one type of sequence. This can be very convenient, and Java 8 introduced a similar capability, called a foreach-loop. In spite of the name, a foreach-loop uses the keyword for. Here is an example:

Get hands-on with 1200+ tech skills courses.