Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 14, 2011, 10:33 AM   #1
Alhazred
macrumors member
 
Join Date: Jul 2011
if/else if statement

I need to control several values in my app and I'm trying to do so in this way
Code:
if(condition 1)
{
   //do something1
}
else if(condition 2)
{
   //do something2
}
else if(condition 3)
{
   //do something3
}
else
{
   //do something else
}
but it looks that only the 1st condition is checked, the other are ignored.
Is it possible to use this kind of control in objective-c? If not, how to do something that behaves like that?
I'm checking if some text fields are filled before to send the data.
Alhazred is offline   0 Reply With Quote
Old Jul 14, 2011, 10:54 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Post the real code. What you are suggesting works just like normal C so there must be something specific to your code. Of course if condition 1 is true we'd not expect any of the other conditions to be checked. If condition 1 is always true this would explain the behaviour you are seeing.
robbieduncan is offline   0 Reply With Quote
Old Jul 14, 2011, 12:41 PM   #3
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by robbieduncan View Post
If condition 1 is always true this would explain the behaviour you are seeing.
Especially if condition 1 is something like:
Code:
if (a = b)
Yes, I purposely meant to only have one equals sign in there.
__________________
dejo is offline   0 Reply With Quote
Old Jul 15, 2011, 04:17 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by dejo View Post
Especially if condition 1 is something like:
Code:
if (a = b)
Yes, I purposely meant to only have one equals sign in there.
That is exactly what I was expecting to see if the OP posted their real code.
robbieduncan is offline   0 Reply With Quote
Old Jul 20, 2011, 02:41 AM   #5
Alhazred
Thread Starter
macrumors member
 
Join Date: Jul 2011
Thanks for your answers, the problem was only due to a lack of attention, what I want to do with this code is to check if required fields of a form are filled in or not.
The problem was that I have a label on the side of each field which shows a text "Field required" if the related field is not filled in, but in the code I had the messages all linked to the 1st label and it seemed to me that the 1st condition was always true.
Alhazred is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
If-else statement not evaluating alexatwater iPhone/iPad Programming 2 Mar 13, 2014 01:38 PM
applescript if statement wild4life2013 Mac Programming 2 Aug 5, 2013 11:16 PM
Why doesnt the else statement work in this? bigMAC28 Mac Programming 2 Aug 4, 2013 04:44 PM
Can someone explain this statement DMB15 iPhone 6 Sep 12, 2012 05:41 PM

Forum Jump

All times are GMT -5. The time now is 08:47 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC