FAQ: Loops - For Loop Demo

This community-built FAQ covers the “For Loop Demo” exercise from the lesson “Loops”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C++

FAQs on the exercise For Loop Demo

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I still don’t quite understand the difference in purpose of the ‘for’ and ‘while’ loops. The example in the given exercise can as well be accomplished by a while loop as it can be by a for loop. Are there any examples where the for loop is exclusively applicable?

So I deleted the i++ after the end of the for loop and it crashed the terminal. I had a good chuckle to myself because I assumed this would happened, but I just want to make sure its because it was trying to run the operation infinitely due to there being no reason for the operation to stop?

:grinning:Question about iterating, in this case the statement would iterate 10 times, then why not write i < 11 ? why adding i++ to add one more iteration? Thank you!!!
int main() {

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

std::cout << "I will not throw paper airplanes in class.\n";



Basic math; When you start at 0 then it’s 10 times at 9 (0,1,2,3,4,5,6,7,8,9) If you started with i=1 then it would have to do either i===10 or i<11 i<10 means to run while i is less than 10 (it stops when i reaches 10

With experience you will note the difference It will be a question of comfortability. Is true that you can use a while for things that you may prefer to use a for and viceversa hope it helps :smiley:

because you start in 0 so from 0 to 9 are 10 values.
You have to increment the counter so It can stop otherwise it will run forever

@eagleeye9117140557 for replying to someone you can use the @ or click reply in his comment so the person can be notified and we can see if there are replys to his comment :wink: