C/C++: Difference between "while" loop and "for" loop ?!?
I went to an interview where the interviewer (who looked pretty knowledgable) asked me, among other things, to write a program in C++ to display the first ten prime numbers... the "first ten", mind you, not "prime numbers less than 10."
Nervous as I was (first interview, please understand!!), I set about the task by inserting a couple of "for" loops here and there... Nothing came to mind, while the interviewer sat there clicking her tongue. After about five minutes, apparently she had had enough, and proceeded to scold me, "See, that's the exact mistake your predecessor made. You should use a while loop.. a for loop won't work for you in this situation.
"What is the difference between a for loop and a while loop?", she asked. This question came as a surprise to me. I tried to avoid the question, "I know the difference between a do...while loop and a while loop." But no, she wanted to know the difference between a "while" loop and a "for" loop...
...And that's where it all ended, I suppose. She scoffed at me and whispered in an undertone, "And you got 87% in aptitude!!" (*****). Anyway, back in the comfort of my home, I wrote a perfect program for the same using >>only<< "for" loops.
And that's why I'm totally bamboozled. I'd like to think that the interviewer was off her rocker, but... "innocent until proven guilty", I suppose. I've asked all my friends the same question, and they all answered the same way I did. I've looked into many books and there's no mention of a difference between the two (on the contrary, they preach ways to convert between them, to add to my frustration!)
Hoping someone would provide me with a satisfactory answer...
Yours frustratingly,
Maelstrom
[BTW: If you don't know how to write the program yourself... DO NOT press the Reply button]