Is it possible to put 'x/10' as a loop_expression in 'for' statement as following:
for ( ; numberD != 0 ; x / 10) {
resultNumber = numberD / x;
开发者_如何学编程 NSLog (@"Display %i", resultNumber);
numberD /= 10;
}
I tried to run this way, but it fails to do it. Any suggestions of how to do it, if I need the loop to divide x by 10 every time?
Untested, but I believe your operator is wrong.
for ( ; numberD != 0 ; x /= 10) {
resultNumber = numberD / x;
NSLog (@"Display %i", resultNumber);
numberD /= 10;
}
I would say better use a while loop instead if for loop.
while(numberD != 0) {
resultNumber = numberD / x;
NSLog (@"Display %i", resultNumber);
numberD /= 10;
x /= 10;
}
精彩评论