+ 2
Different between for loop and foreach loop.
how do work ? define that.
3 Réponses
+ 3
C++
for (init; check; inc) ...
equals
init;
while (check)
{
...
inc;
}
A foreach loop is more specialised than the for loop and it goes through each element of a data structure.
+ 2
for loops just increment ot decrement a counter by a set amount each iteration.
a foreach loop takes a data array or object and on each loop gives you access to the key value pair for each element in the structure. you can do that with a for loop but a foreach makes it easier.
I
for (var i = 0; I < array.length; i++) {
//array[i].key returns value for that key in an array of objects
}
+ 1
In Python, a for loop is kind of like a foreach loop in other languages: it iterates over an object