Loop does not run on Xcode

Asked

Viewed 135 times

4

I’m trying to run a loop in the Xcode, but it doesn’t work.

On the console gets:

Type the loop number:
5

Nothing else happens in the terminal. 0,1,2,3,4,5 does not appear.

In short, it stands still after I type any number, however, from what I saw, it is still running, I have to give a stop to be able to run again.

The debug Session:

I put a breakpoint in the variables and gave a stepover

deub

This has to do with @autoreleasepool? Same goes for mine switch.

My code

#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]){
     @autoreleasepool {
        int i, usuario;
        NSLog(@"Digite o numero do loop: ");
        scanf("%i", &usuario);
        for (i=0; i<=usuario; i++) {
             NSLog(@"%i", i);
        }        
     }
 return 0;
}

The project was created in Foundation, Command Line Tool.

  • Added some more information.

  • I added what was missing.

  • When the Debugger is stopped on the line scanf(), press F6 (Step Over). At this time, the scanf() is executed and you must enter a number followed by the Return key. After that, the Debugger must move to the next line, the one containing the for. In your case, what exactly occurs in each of these steps?

  • Well, the Debugger is marked on the scanf line, with a (lldb) at the end of the console, when I press F6, the line that marks the Debugger is gone, as well as the (lldb), so I type any number and give enter, but nothing else happens, it seems that it doesn’t even enter the for...

1 answer

1

Make sure you don’t compute the loop?

I think the mistake lies in having the variable "%i" which I think should be just "%d" or else "%f" float:

#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]){
     @autoreleasepool {
        int i, usuario;
        NSLog(@"Digite o numero do loop: ");
        scanf("%d", &usuario);
        for (i=0; i<=usuario; i++) {
             NSLog(@"%d", i);
        }        
     }
 return 0;
}

Anyway advise to by printf’s along the code section.

Regards.

  • Still the same problem. I added some more information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.