Why do for loops exist? Why not just an if statement and a goto? What exactly do they add?

Why do for loops exist? Why not just an if statement and a goto? What exactly do they add?

They add an additional layer of abstraction.

Why do compilers exist? Why not just write in ones and zeroes?

please program in some old basic, they handle loops like that

>if statement and a goto

For fucks sake have you never played with x86 assembly?

You don't even need an if statement.

Why are we here? Just to suffer?

goto tends to produce buggy code

Not the same thing.
I know. But why do programming languages have this feature? It's just needless bloat.
How?

>goto
>ever in anything high level

>we do functional languages have a map function
>just recursively call the same function again over and over and use if
>so much better than passing it in
>why can't programming be harder please

Lambdas are the dankest meme

Not the same thing.

>for loop:
for(int i=0; i == n; i++) {
...
}

>goto
loop: do {
...
}
if i == n goto loop;

loop: do {
...
}
i++
if i == n goto loop;

loop: do {
...
}
if (i++==n) goto loop;

>retardedly """clever""" code: the post

kek

here you have a do..while loop, it will always execute the code at least once, so it's not the same.
Also would you kindly fucking declare i somewhere?

>using goto

>it's just needless bloat
Why, programming languages are just needless bloat. Why not simply write in Assembly which is what actually gets executed by the computer?

Goto was the begining of the considered harmful meem

because its easier and you shouldnt have to worry about that when your writing high level code. Its adding difficulty for no real reason. "needlessly bloat" jesus maybe a little but its not like your codes going to run that more effecient when you replace all loops with goto's

because you're a faggot noob

programming is all about making the programming process shorter.

for wraps two statements into one and forces a consistent program flow.

good luck looping through an array

convenience

>What exactly do they add?
Not littering your codebase with labels.

>It's just needless bloat.
It's called syntactic sugar, and it's not bloat. It adds nothing to the generated assembly that you would not have generated with an if statement and a goto.

>using goto
kys faglord, but seriously for loops keep things easy, understandable and safer, you know you are safe inside a for loop, if you forget about a goto it can be catastrophic.

Code is written for people, not compilers, and should be written in a way that documents intent.

>assembly gets executed by the computer
stop posting

Assembly is harder to write, debug, and read.
But it isn't. Explain how this:
int i = 0;
loop: do {
...
}
i++;
if i == n goto loop;

is harder to read than this:
for(int i=0; i == n; i++) {
...
}

start at 0, increment by one, until i = array length.
That ia a good point. But surely it could be solved somehow, such as scope-specific labels?
But it doesn't make the structure immediately more apparent.
Which is what goto does.

>>unknown reference i

ASM is fine man, just have to know where your registers be

>But it isn't. Explain how this:
>int i = 0;
>loop: do {
> ...
>}
>i++;
>if i == n goto loop;
>is harder to read than this:
>for(int i=0; i == n; i++) {
> ...
>}

are you literally fucking autistic?

1) count the fucking symbols
2) what do you do if you have multiple loops in sequence? nested? do you count them all out?

you know, I'd laugh at you too, but I actually have to give you props. never thought of that

for(;i++

>But it doesn't make the structure immediately more apparent.
it does, but just slightly.
It is a C feature, which doesn't have the primitives that allow for us to do
for i in (1..10):
print i

as in ~~python, or
map \x -> 2*x [1 2 3]
[/spoiler]
as in ~~ML.
It's a limitation of the language and because it was a popular language, it was adopted by it's descendants.

it also keeps the loop infrastructure in just one line, instead of 2 or 3.
But yes, it's a weak abstraction.

Kill yourself, you dumb fucking shit stain.

this is why pajeets have taken over

> (OP)
>>goto
>>ever in anything high level
>>using goto
> (OP)
>>using goto
>kys faglord, but seriously for loops keep things easy, understandable and safer, you know you are safe inside a for loop, if you forget about a goto it can be catastrophic.
>this is why pajeets have taken over

>Using goto