0
For( ; number !=0; number /=10)
I didn't understand it can you help me with this
5 Réponses
+ 1
What exactly do you not understand?
+ 1
Okay. Do you understand the basic pattern that's in every lesson?
for (int i=0; i<10; ++i)
The first part sets up a variable at 0; the next part says that the loop is to be repeated until i becomes 10; the third part increases i with every loop. So that loop runs 10 times.
You can define all sorts of conditions and actions to steer a loop. In your case, there is no need to set up a variable because 'number' was already defined before. So the first slot remains empty.
The second slot, the condition says that the loop shall go on as long as number is not zero.
And in the third slot, number is divided by 10, so eventually it will be zero and the loop will be over (under the condition that number is an int).
0
For loop statement
0
number=num
for(;number!=0;number/=10)
is equivalent to for(number=num;number!=0;number/=10)
If it was the problem