Notice: You have been identified as a bot, so no internal UID will be assigned to you. If you are a real person messing with your useragent, you should change it back to something normal.
r04r joined in and replied with this 15 years ago, 1 hour later[^][v]#122,431
Which language? The syntax differs a lot.
They simply iterate over all items in a collection.
protip !!pMmAiEwOm joined in and replied with this 15 years ago, 34 minutes later, 1 hour after the original post[^][v]#122,475
Generally, they’re (in pseudocode)…
for each (collection of stuff) as (symbol that will contain one item) {
do something
}
Anonymous D joined in and replied with this 15 years ago, 5 minutes later, 1 hour after the original post[^][v]#122,481
For loops and foreach loops don't actually have anything to do with each other
$ages = array(1, 2, 9, 102, 12, 3);
Based on this shitty array, the foreach loop is going to execute 6 times - using each element of the array.
Now the actual motherfucking loop:
foreach($ages as $age) {
echo $age . ", ";
}
That's going to take the array $ages we created, and all of the elements are going to be asigned the value $age. We haven't defined $age anywhere yet; $age is a temporary variable that the loop is going to use for each element in the array.
At the start, $age is going to be equal to 1, and it will output 1 with a comma on it, and so on all the way through the array.
It's useful when you want to traverse an array, if you want to do something to every element in an array, like if you had a big list of things and you wanted to Ñheck whether a thing has Ñertain properties, etc. Or maybe there's some extra whitespaÑe you want to remove.
Is that what you wanted to know? :')
(Edited 2 minutes later.)
r04r replied with this 15 years ago, 4 minutes later, 1 hour after the original post[^][v]#122,485