You are here:

C++/C++ Loops

Advertisement


Question
hi
sir,what is difference between while and for loop?.In terms of
for loop. it outputs one number greater than what we want to output
for ex
for(x=0;x<7;x++){
cout<<x<<endl;}it outputs 0to6 numbers.
yet 0 to 6 numbers are still 7 numbers.further when we change x<7 to x<=7.it ouputs 0 to 7 numbers which is still  8 num.
can you explain me why?

Answer
It just counts from the starting point you give it to the ending point you give it. You stated that x should start from 0 and should stay less than 7, so it printed 0 to 6 because all the numbers in this limit meets the specifications you have described. Similarly it did in the second statement you have mentioned. If you want to output 6 digits then you should give first condition to be x=1. Hope you are getting my point.


Regards
Tehreem

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tehreem

Expertise

I can answer questions related to C++ coding and programming techniques.

Experience

I am a C++ programmer.

Organizations
University of Engineering & Technology Lahore

Publications
http://recurseit.blogspot.com

Education/Credentials
I am doing BSCS.

©2016 About.com. All rights reserved.