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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
How do you form if statements, -> if variable is set? ct2k7 iPhone/iPad Programming 4 Jan 23, 2010 05:30 PM
if/else statement giving errors captainmeowtron Web Design and Development 10 Aug 17, 2009 02:41 PM
If Else, statement not working properly. jjgraz iPhone/iPad Programming 4 Apr 19, 2009 04:22 PM
Help with basic if statement Buschmaster Mac Programming 2 Mar 11, 2008 03:49 PM
php-display a form on if statement jordanste Web Design and Development 6 Mar 4, 2008 10:42 PM


All times are GMT -5. The time now is 05:07 PM.

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

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