Explaining Loop π 1.
Loop is the fundamental building block of programming, used to repeat or iterate the fixed number of steps.
Loop saves the time and labour.
2. Real time example
Suppose you are donating $100 to each one of the 50 homeless.
For that you will keep count of people who are you done with.
So, 3 things we r doing:
β’ setting condition to 50
β’ counting ( increment )
β’ donating
3.
There are many ways out there to implement loop in programming:
β’ foor loop
β’ while loop
β’ forEach
β’ do while
and many, you can also develop your own.
4. syntax or format to write the loop in programming varies as per loop we implement, but for the most common loop which is for loop is following syntax:
for( let person = 0; person < 50; person++ )
{
donate_100();
}
loop ends when 50 persons are donated $100.
5. Consider syntax as the sentence structure for writing the programming statements.
there is a particular format predefined for every programming language to write the statement. what we call syntax in programming terms. #DEVCommunity#100DaysOfCode
6. forEach() loop 1/3
-It is asociated with array with a callback function once 4 every element.
-It has 3 parameters( value,index,array)with the fixed position(no matter what name u choose 4 them).
-returns undefined.
array parameter represents the actual array.
6. forEach() loop 2/3
syntax π
array.forEach(value, index, array)
{
index and array are optional.
}
6. forEach() loop 3/3
another example for array parameter to understand it bit more.
β array parameter prints the actual array, number of times its length is.
[1,2].forEach((value,index,array)=> console.log(array)) will print [1,2]x2 times.
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh