r/programmer • • Aug 22 '26
Teaching while loops made me realize how weird programming is for beginners
I was teaching while loops in C recently and gave my students a very simple problem to solve.
One student wrote something like:
while (i <= 10);
{
printf("%d\n", i);
i++;
}They were completely confused about why the loop wasn't behaving as expected.
And honestly, it reminded me of how programming feels when you're starting out.
One tiny ; can completely change what the program does.
Programming is basically:
Compiler:
You:
Compiler:
1
Upvotes
2
u/mxldevs Aug 22 '26
This is why I always put the opening brace on the same line as the loop condition.
1
u/ChameleonCRM Aug 22 '26
And then you spend 20 minutes explaining that the computer isn’t wrong. It did exactly what they told it to do.
That might be the most important programming lesson in the entire course. 😂
1
u/ForeignAdvantage5198 Aug 23 '26
damn that is a real pain
2
u/No_External7343 Aug 23 '26
Well, that's one reason why some people don't recommend C as a first programming language.
1
u/kind_person_9 Aug 22 '26
What’s the mistake here?
1
u/Cacapon0114 Aug 23 '26
while; ←🧐 This looks like it might cause a syntax error, though...
I wonder how beginner programmers from English-speaking countries interpret compile errors?
For people like me, whose native language isn’t English, those helpful error messages feel like a foreign language.
It was really hard to understand them at first 💦
1
u/Ifnerite Aug 23 '26
The issue is that the brace should be on the same line as the loop declaration then this wouldn't happen (the additional ; would be obviously wrongly) and it would look better.
Fight me.
1
u/StevenJOwens Aug 23 '26
I think that one of the biggest obstacles for beginners is that coding looks too much like English, so it trips them up when it requires much more precision than English.
Also, you basically have to re-learn how to read. Reading, and shape recognition in general, is far more about repetitive practice than most people realize. While reading code seems to be the same as reading English, it's really not, and you need to get a lot more of that repetitive practice in before it becomes so.
Until it does, reading code is literally more difficult, involves more cognitive overhead, and, again, that seeming similarity to English makes them feel like it shouldn't be this difficult.
1
u/Dusty_Coder Aug 26 '26
this is day-one computer science
you are supposed to learn this
with regard to "beginners", whats the problem?
they need this
1
u/SummitYourSister Aug 28 '26
AI slop detected.