Differences between if() and for()
Hi there, I'm just new into learning C++, enjoying it alot too! But I want to learn too quickly and find myself having to backtrack alot.
My question is this, I'm up to the loop chapters and have been learning everything about the "if" statement and now it goes to the "for" statement, far as I can see "for" is wayyy better but since I'm new at all this, is it!?
The book will probably tell me later but as I said, I want to know NOW :)
Can I do everything I would do with if with for?
With the for statement I don't need a "goto" statement and as far as I've heard you don't want to use the "goto" anyways.
The for|do|while statements act completely nicer than if, sometimes cutting down 90% of the lines.
Hate to bother you people with this newbie question but that's what a forums for right!
Last post to close this thread
I completely understand now and have tested it out, here's my example to what you've showed me:
Bye Until the next question!
using namespace std;
int i = 1, first = 0, max = 0;
cout << "\nEnter the starting number: ";
cin >> first;
cout << "\nEnter the ending number: ";
cin >> max;
cout << "\n";
if(first >= max) // :D
cout << "There was an error, you cannot count in a incrementing fassion\n"
<< "from " << first << " to " << max << ".\n"
<< "Please re-start this program and try again.\n";
for(; first <= max; first++) // :D
cout << "First number: " << first << " incrementing to: " << max << "\n";