Quote:
Is it necessary to initialize a variable under the while loop ?
Variable initialization is mandatory, everywhere, for every variables.
Variable initialization means that you must store a value in the variable before any attempt to use its contain.
while(i = 0 )
Here the initialization of
i
is misplaced because this place is for loop condition and the 0 will prevent from entering the loop.
i = 0;
while(i == 0)
{
...
}
This is probably what you want to do as suggested by OG.
a = 10;
while(i = a)
{
...
a--;
}
but this is working because it means.
while((i = a) != 0)