4 ms·
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 (
by svachalek 2y ago
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.
- salawat 2y ago//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.