+ 1
double semicolon.
What's the difference when we use double semicolons before the last parameter in the for loop .. ?
3 Answers
+ 3
If you see a double colon, then it just means that a part of the for loop is being missed out for whatever reason, which is absolutely fine, it will still compile.
Example:
int x = 0;
for (;;x++)
{
if (x == 10)
break;
}
We are missing the declaration in the first part of the for loop, which is fine, because you don't always have to declare one.
We are also missing the base case of the loop, the second part which would usually cause an infinite loop, however due to our if statement, it is not infinite.
We have our increment in the last part of the for loop, so that the if statement will actually eventually execute. If we removed that last part of the for loop, this will turn in to an infinite loop, unless we incremented inside the body.
+ 1
Thanks,, but how did you know that x=0 is the initial value?
+ 1
When U Declared The Variable x , The Variable x is also initialised with a value 0 ..
See The Codes ... Before The Loop There Is A Statement int x=0; .. That's The Reason ..