Java Essentials - For each loop in java
589 views
Nov 18, 2024
Java Essentials - For each loop in java Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Arnab Chakraborty, Tutorials Point India Private Limited
View Video Transcript
0:00
In this video we are discussing 4-H loop in Java
0:05
In the previous video we have discussed what is the 4-loop. So it is the 4-loop actually but in some different syntax
0:12
So 4-Each loop is mainly a 4-loop but with the different syntax and this loop helps us to iterate
0:18
through all of the items of an array or on the collections
0:24
So let us go for the basic syntax of this 4-E-loup. So, for data type items, and this is the collection of multiple elements
0:34
So for each and every iteration, one of the elements will initialize these items, and this
0:40
item will be executed according to the statement written in this for each body
0:46
So let me explain it once again. So here we are having this collection, collection of elements
0:51
Also it can be one array. For data type item, this item will get initialized with one of the items
0:58
of the item values or element values from this collection for each and every iteration distinct
1:05
items will initialize this item and then the statements which will be written under this
1:10
curly braces will be executed for the current element in the item variable from the collection
1:17
it can store elements one by one in the variable item and follow the next instructions
1:24
written in the curly braces the type of the item and the collection must be same that means the this item type and this collection element type must be same so let us go for one practical demonstration for the easy understanding of
1:40
the implementation of 4-h loop in our Java programming in this demonstration
1:46
we're discussing about 4 each loop we're defining one integer array and the
1:52
array is having this set of values so how many values we're having here
1:56
eight values we're having here so now using the 4-h each So for I and D value colon array, that means here for each and every iteration for each and every looping and one value will be picked up from the array and at a time only one value will be picked up and that will be kept in the variable value and then the value is going to get printed
2:18
So now let me go for the execution you can find that. So 56, 74, 14, 51, 16 and 42, 72, 74 and these values have got picked up in the same order
2:28
that means for each and every iteration for each and every looping using this for each
2:33
statements you can find that it is picking up one value at a time and automatically next
2:38
time it is taking the next value from this integer array so this is a very good
2:43
example of this for each where we're having one integer array and in the loop the
2:49
integer array values are to be picked up one value at a time in the same sequence
2:55
in which they are occurring in the integer array and array and in this way for each and re-itertation I'm going to print a new value which
3:03
has been picked up from the integer array so that is an example of for each loop
3:07
in Java thanks for watching this video
#Java (Programming Language)