This highlights just how bad I am at maths. I'm doing an exercise on chapter 2 and it gives you the following:
"What is the value of x after this code is done"
int x = 0
for (int y = 0; y <10; y+=2 )
{
if( y == 4 )
continue;
x++
}
Now the answer is 4 but I don't see how. I read it like this. On the first loop y = 0 and so the code executes and x now = 1 and y = 2, on the second time round x = 2 and y is now 4, so the next time it tries to run it see's y is 4 and the continue means it goes back to the start without incrementing x thus meaning it would loop forever?
Edit: If someone could tell me how to do those little code windows as well that would be lovely.
"What is the value of x after this code is done"
int x = 0
for (int y = 0; y <10; y+=2 )
{
if( y == 4 )
continue;
x++
}
Now the answer is 4 but I don't see how. I read it like this. On the first loop y = 0 and so the code executes and x now = 1 and y = 2, on the second time round x = 2 and y is now 4, so the next time it tries to run it see's y is 4 and the continue means it goes back to the start without incrementing x thus meaning it would loop forever?
Edit: If someone could tell me how to do those little code windows as well that would be lovely.
Create a custom theme





Use [source lang="c#"]...[/source] tags for those scrolling code boxes. [smile]