This code computes the integer powers of two going from 0 to 9. I was able to follow it for the first two cout statements:
2 to the 0 power is 1
2 to the 1 power is 2
But after that I lose it. It's a hard program for me to understand.
One thing I need to know is this: When you are working with a nested loop, does the inside loop (in my case the while loop) go to it's total completion, before the program goes back to the top of the outside loop (the for loop)? I was of the
understanding that the inside loop goes to completion before program flow goes back to the outside loop. But I don't know now. I'm currently doing this in C ++, but I will be doing it in C# too. Plus when I run the program I'm
getting an infinite loop and I don't know why that is.
The code is:
2 to the 0 power is 1
2 to the 1 power is 2
But after that I lose it. It's a hard program for me to understand.
One thing I need to know is this: When you are working with a nested loop, does the inside loop (in my case the while loop) go to it's total completion, before the program goes back to the top of the outside loop (the for loop)? I was of the
understanding that the inside loop goes to completion before program flow goes back to the outside loop. But I don't know now. I'm currently doing this in C ++, but I will be doing it in C# too. Plus when I run the program I'm
getting an infinite loop and I don't know why that is.
The code is:
C#:
int main()
{
int e;
int result;
for (int i = 0; 1 < 10; i++)
{
result = 1;
e = i;
while (e > 0)
{
result *= 2;
e--;
}
cout << "2 to the " << i << " power is" << result << endl;
}
cout << endl;
system("pause");
return 0;
}