I tried googling something about this topic, but couldn’t really phrase it properly.
I was staring at my code and started thinking about what does “for” in for loop stand for? I mean, it just doesn’t make any sense to me
I tried googling something about this topic, but couldn’t really phrase it properly.
I was staring at my code and started thinking about what does “for” in for loop stand for? I mean, it just doesn’t make any sense to me
For each element in a set we do something.
for(int x = 0; x < 100; x++) { ... }
for an integer value x starting at 0, always smaller than 100, that increases in +1 per iteration, do stuff.
The for…each algorithm looks like this:
for(string value : collection){ ... }
Which means, for each string in the collection, do stuff.
You can think of it as shorthand for a while loop, so:
for(initialization; conditional; step) {
action;
}
is the same as
{
initialization;
while(conditional) {
action;
step;
}
}
Obviously the for loop is more readable (especially for programmers) and more compact.
I know that Was just thinking what for actual ‘for’ stand for. Already found my answer.
I wasn’t trying to imply that you didn’t know what a for loop did. I thought we were just posting our thoughts on the for loop.
For either means Forever until or For every in;
Example
foreveruntil(x = 0; x < 5;x++); foreveryin(objecta:arrayb);
Not foreveruntil but foreverwhile.