r/cprogramming • • Oct 25 '26

what is the difference between a (specifc) while loop and a (specific) for loop (read body)

what is the difference between

for (i = 0; i < 10; i++) {}

and

i = 0;
while (i < 10) {
i++;

}

edit: thank you all for commenting, now i know, and u/deckarep, no not homework, just a question, to see if there were any difference

12 Upvotes

47 comments sorted by

View all comments

Show parent comment

0

u/Rararror Oct 26 '26

"continue" IS JUMPING. Every jump goes in a well defined place. 

Why don't you just label somewhere and "goto" it so you "skip a lot going on" ?

Conditional blocks and variables have the benefit that you are forced to think what you are doing. Oftentimes thinking about how to solve the logic simplifies things.

Writing code IS thinking.

2

u/fllthdcrb Oct 26 '26

I didn't say it isn't jumping. I said it isn't jumping "all over the place".

Why don't you just label somewhere and "goto" it so you "skip a lot going on" ?

Still less elegant than a single continue.

Conditional blocks and variables have the benefit that you are forced to think what you are doing. Oftentimes thinking about how to solve the logic simplifies things.

They also create more opportunities to screw up the logic. One must always be thinking about the logic, but not make things more complicated than they have to be.

1

u/Rararror Oct 26 '26

"all over the place" means you break the structured programming paradigm. You ALWAYS jump somewhere well defined, you don't jump at random. Are you serious? 

not make things more complicated than they have to be.

You can easily oversee a "continue" buried in a convoluted loop than having to follow and understand the logic of the structure of conditional blocks. It also makes finding bugs harder.

2

u/fllthdcrb Oct 26 '26

"all over the place" means you break the structured programming paradigm. You ALWAYS jump somewhere well defined, you don't jump at random. Are you serious?

"All over the place" sounds a lot like not a well-defined place to me. But thanks for making yourself clear.

You can easily oversee a "continue" buried in a convoluted loop than having to follow and understand the logic of the structure of conditional blocks.

True. But if that's a problem, then maybe some refactoring is in order, to make the loop less convoluted, rather than blaming continue.