开发者

Loop_expression in 'for' statement in Objective-C

开发者 https://www.devze.com 2023-04-06 17:07 出处:网络
Is it possible to put \'x/10\' as a loop_expression in \'for\' statement as following: for ( ; numberD != 0 ; x / 10) {

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;
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消