-3
if (stash != 0) {
            for (i=1; i<=6; i++) {
                a[1][i]=a[1][i]/stash;
            }
        }
        else
        {
            NSLog (@"Matrix is Not Invertible");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Matrix is not invertible!" delegate:nil cancelButtonTitle:@"Review Input" otherButtonTitles:nil, nil];
            [alert show];

        }

I Want to stop the program if the variable "stash" is zero, but i can't use break since it's not in a loop, i wanted to use return but it says that void should not return any value... what should i do to get this working? thanks for all your help....

2 Answers2

0

I don't know if you need to exit the method only but you could use:

return;

or redefine the method to return an integer -(int)myMethod; and then return 0;

mangusbrother
  • 3,988
  • 11
  • 51
  • 103
  • 1
    No don't redefine the method that would be pointless just use `return;` – Popeye May 29 '14 at 11:09
  • You'd redefine it maybe if he wants to return an exit code to know if it was successful or not. I can't really tell what he wants. – mangusbrother May 29 '14 at 11:12
  • Well that would still be wrong you shouldn't use `exit()` at all in iOS as it makes it look like the application has crashed. – Popeye May 29 '14 at 11:17
  • I meant exit code for the method so he can tell if it was successful or not. not exit() the whole application. As I don't know where this method is being used i can't really tell what would be ideal. – mangusbrother May 29 '14 at 11:49
0
//Add return statement, returning nothing
return;



- (void)yourMethod {


  //your code


  //your declerations

  if (stash != 0) {
    for (i=1; i<=6; i++) {
      a[1][i]=a[1][i]/stash;
    }
  }
  else
  {
    NSLog (@"Matrix is Not Invertible");
    UI *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Matrix is not invertible!" delegate:nil cancelButtonTitle:@"Review Input" otherButtonTitles:nil, nil];
    [alert show];

    //Add return statement here, returning nothing
    return;
  }


   //other code in your method
   //your code

}
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184