DEV Community

while loop and for loop are not the same in C/C++

csm on November 15, 2026

I was writing a small parser logic in C++. I previously wrote it in another language, so I knew it before hand. Wrote the code, looking good, confi...
Collapse
 
technogamerz profile image
𝐓𝐡𝐞 𝐋𝐚𝐳𝐲 𝐆𝐢𝐫𝐥 •

Writing parser/lexer loops with for syntactic sugar is a classic rookie trap. The moment you hit a branch where token consumption is conditional, giving the compiler automated epilogue control (i++ via continue) completely corrupts your state machine. You end up with a silent AST desync that takes hours of gdb tracing to isolate. Solid post!

Picked as gem
Collapse
 
csm18 profile image
csm •

Aur aap kehte hai ki humse kuch sikh sakte hai!
All the technical terms, took some time for me to understand 😂
But, true, a simple increment can break all the logic! 😊

Collapse
 
technogamerz profile image
𝐓𝐡𝐞 𝐋𝐚𝐳𝐲 𝐆𝐢𝐫𝐥 •

Nowadays, if you write heavy words, it is assumed to be AI-generated.lol xD

Thread Thread
 
csm18 profile image
csm •

Jokes aside, I never thought of your words as AI.
Writing with tech words means you have much more deeper knowledge!
Upto to what I know, you pretend like you don't know much, but you are a pro!

Thread Thread
 
technogamerz profile image
𝐓𝐡𝐞 𝐋𝐚𝐳𝐲 𝐆𝐢𝐫𝐥 •

Thanks 😊, but I'm not a pro 😂

Collapse
 
effessdev profile image
EffessDev •

🙀

Collapse
 
technogamerz profile image
𝐓𝐡𝐞 𝐋𝐚𝐳𝐲 𝐆𝐢𝐫𝐥 •

I almost missed this post because of @akhourianmolkumar and @effessdev ! How much do you two comment? I finally found it on my home page

Collapse
 
csm18 profile image
csm •

😄
You read all posts and of everyone 🙌🙌🙌

And my post on home page? wow!

Thread Thread
 
effessdev profile image
EffessDev •

I also read your posts. They are short and high value. I like short posts!

Thread Thread
 
csm18 profile image
csm •

Yep! You and @technogamerz and some others are my only readers!
Thank you!

Thread Thread
 
effessdev profile image
EffessDev •

😇

Collapse
 
hemapriya_kanagala profile image
Hemapriya Kanagala •

As always, such an easy article to follow along with, bro! I've never touched C++, so I didn't know about this difference between while and for loops when using continue. Pretty cool to learn something new 😀

Collapse
 
csm18 profile image
csm •

Thank you 😊