News for hackers. Stuff that matters.
Re:Misconceptions about loops in C by tedunangst on Thursday June 27, 2024 @03:17PM (#40813996)
This is what happens when we eliminate shop class. Sand this table leg. Good. Now do that three more times. Kids used to know loops before they ever touched a computer.
Re:Misconceptions about loops in C by klyrs on Thursday June 27, 2024 @03:41PM (#40814259)
Exactly. Go make a table with 4 legs and also every leg has 4 legs. Now you get recursion and a very steady table.

You were a kid in shop class. Now you want your kids to take shop class. Because, recursion.

Re:Misconceptions about loops in C by adwn on Thursday June 27, 2024 @04:17PM (#40814621)
> Go make a table with 4 legs and also every leg has 4 legs.

If you have to make up nonsensical examples to prove your point, then you probably don't have a point.

> You were a kid in shop class. Now you want your kids to take shop class. Because, recursion.

That's not recursion.

Re:Misconceptions about loops in C by klyrs on Thursday June 27, 2024 @06:07PM (#40815699)
The first paragraph was more of a parody of your just-so argument than point per se; but the second paragraph is literally recursion.
Re:Misconceptions about loops in C by nequo on Thursday June 27, 2024 @04:54PM (#40814984)
How is it not recursion?

  def spawn():
    take_shop_class()
    return spawn()
Re:Misconceptions about loops in C by svachalek on Thursday June 27, 2024 @07:58PM (#40816497)
C doesn't have a "do this 3 times" loop though. It has an "initialize counter to 0 first, increment counter after each operation, and compare the counter to 3 (or is it 4?)" loop. Kids definitely don't get this without being taught.
Re:Misconceptions about loops in C by salawat on Sunday June 30, 2024 @06:04PM (#40840759)
//Precon: Need 4 legs. Have none.

Int counter_of_sanded_legs = 0;

do{

Sand_a_leg; Counter_of_sanded_legs++;

} While (counter_of_sanded_legs < 4);

Need four legs, have none. Doing while I don't have enough. How many legs do I have? 1. Doing. How many legs do I have? 2. Doing. How many legs do I have? 3. Doing. How many legs do I have? 4. Done.

Alternatively:

for (int i=0;i<4;i++;) {

//how we start; whether we repeat; how we update our counter.

Sand_leg();

}

You only need to sand a leg when you don't have enough legs.

These aren't that far off of actual things you'd do moving about. In fact, not realizing that you're distilling something physical into the symbolic is a leading cause of confusion in my experience.

A "do x times" dedicated looping construct would be syntactic sugar that detracts from understanding what the underlying semantics are; which if you're teaching how to program is a bad idea. The idea is to have your understanding precede the machine. Not lag behind.

You can start screwing around with abstractions after you get the basics. As once you have the basics, you can compose them into any form you want.

The rest is just increasing levels of crippling mental illness.