iOS if/else if statement

Alhazred

macrumors member
Original poster
Jul 5, 2011
35
0
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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
24,752
130
Harrogate
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.
 

Alhazred

macrumors member
Original poster
Jul 5, 2011
35
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.