Newbie Question, Need clarification on for loop
Code:
#include <iostream>
using namespace std;
int main()
{
for(int x = 0; x < 10; x++)
cout << x <<endl;
cin.get();
return 0;
}
BTW, I am using the tutorial Cprogramming.com Tutorial: Loops
I understand how for loops work. (mostly) I know this prints x while x<10(in this case). Which I have tested and worked fine.
As I was writing this I answered my own question I believe, just want to make sure.
For example this is what I see:
Code:
for(int x = 0; x < 10; x++)
Is this the same as?
Code:
int x = 0;
for( x <10; x++)
The reason I ask this, originally in the first example my mind tells me that it will set x = 0 everytime it gets evaluated. But as I was writing this I realized x is just a variable that is assigned (0) so the compiler skips this part of the for statement correct?
I know there are better ways to write this piece of code I am just trying to grasp everything in the tutorial and practice it.