Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why are for loops called for loops? [SOLVED]

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

I use for loops all the time. Whether it's numerical or generic, they are very useful loops. But then, the other day, I was thinking. Why are they called 'for? It doesn't make a lot of sense when I think about it in English. Does anyone know why they named this very useful loop a 'for' loop?

Examples of a for loop:

for i = 1,10 do
    print(i)
end
for i,v in pairs(Workspace:GetChildren()) do
    if v:IsA("BasePart") then
        v:Destroy()
    end
end
0
Maybe like do i FOR 10 times. wjs3456 90 — 10y

2 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

for loops names come from "for each", or because it is re-executed "for" each particular value the loop takes on.


Its usage in programming descends from ALGOL (and originally the German keyword für) according to Wikipedia. ALGOL is an old programming language (1950s) that is not used much in modern times, but was very influential on most future programming languages.


For example,

for i = 1, 10 do

could be read as "Do [the following] for each number 1 to 10."


for _, child in pairs(workspace:GetChildren())

"Do the following for each child"

Ad
Log in to vote
0
Answered by 10 years ago

There are 2 reasons I could think of For sounds like number 4. It can be used to indicate the number of success out of a specific number of attempts. It could also be used for objectives purposes so running a command a set number of times could also count as a reason.

0
That does not make sense.. If they wanted it to be four the wouldn't put for. Perci1 4988 — 10y

Answer this question