‫Welcome back.
‫We learned about arrays, how to create them, how to store values in the array and how to access elements
‫in the array and print them according to the index.
‫In this video, we'll learn about a special kind of loops called the for each loop in Java.
‫The for each loop, also known as the Enhanced for loop, provides a convenient and concise way to iterate
‫through elements in the array or collection.
‫It simplifies the process of traversing elements and is particularly useful when you don't need to access
‫the index of the elements and you want to focus on each individual element itself.
‫Exactly as this example here we access the elements of.
‫Specified index, but what about getting all the elements in the array?
‫We need to use the for each loop.
‫So always use for each loop when you have arrays.
‫The basic syntax of the for each loop is as follows.
‫Start by for keyword.
‫We start by specifying the data type.
‫The element to this column and the collection.
‫And here the code to be executed for each element in the collection.
‫I want from you to write this note in your copy book and The Notebook, because this is the basic syntax
‫for the for each loop.
‫Let's break it down.
‫The data type in the for each loop refers for the elements in the collection.
‫It's the data type of the elements in the collection.
‫In this case it's an int.
‫Okay, because our array is an integer element.
‫The element is a variable that represents each individual element in the collection.
‫During each iteration of the loop, the collection, the array or collection that you want to iterate
‫through.
‫And in this case it's the numbers array.
‫So let's iterate through our numbers, array and print all the elements inside it.
‫I commend this because this is the basic syntax.
‫We start with a for loop and the data type according to this syntax is int the element.
‫I'll keep it.
‫You can specify it as element or a number or whatever you want.
‫You can name it whatever you want, and here we specify the collection or the array.
‫Later on we'll talk about collection in the next sections.
‫But now focus with me about this array here.
‫I'll make it as collection or array in order to understand it.
‫Well, numbers array.
‫Okay.
‫So I am getting.
‫Every iteration I'll create a variable called num.
‫And specified it to the elements of the numbers array.
‫Here the code to be executed For each element in the collection, I need to print out each element in
‫this collection or in this array.
‫Print out the number just to print out the number.
‫Okay.
‫Let me run.
‫Congratulations, guys.
‫We succeeded in printing out all the elements of the array with the help of the for each loop.