<Back

Conditions

>
Next

Reference: Apple Developer Page

 

if ( condition is true ) {
// run this code
// ...

}

Operators

Type
Which is
Example
>
greater than
5 > 4 is TRUE
<
less than
4 < 5 is TRUE
>=
greater than or equal
4 >= 4 is TRUE
<=
less than or equal
3 <= 4 is TRUE
==
equal to
5 == 5 is TRUE
!=
not equal to
5 != 4 is TRUE

Variables

Type
Which is
Example
Memory Size
int
integer
..., -2, -1, 0, 1,2
4 bytes
float
floating number
0.23, 0.3, 34.07
4 bytes
double
long number
0.4689357
8 bytes
char
character
A, F, Y
1 byte
string
string
"Words used"
bool
boolean
True or False

Switch

switch(row)
{
case 0:
self.pickerSelection.text = @"Happy";
self.myImageView.image = Happy;
break;
case 1:
self.pickerSelection.text = @"Dopey";
_myImageView.image = Dopy;
break;
case 2:
self.pickerSelection.text = @"Doc";
_myImageView.image = Doc;
break;
case 3:
self.pickerSelection.text = @"Bashful";
_myImageView.image = Bashful;
break;
case 4:
self.pickerSelection.text = @"Sleepy";
_myImageView.image = Sleepy;
break;
case 5:
self.pickerSelection.text = @"Sneezy";
_myImageView.image = Sneezy;
break;
case 6:
self.pickerSelection.text = @"Grumpy";
_myImageView.image = Grumpy;
break;
case 7:
self.pickerSelection.text = @"John";
_myImageView.image = John;
break;
}
}

Else

Sometimes when the condition in an if statement evaluates to false, it would be nice to execute some code instead of the code executed when the statement evaluates to true. The "else" statement effectively says that whatever code after it (whether a single line or code between brackets) is executed if the if statement is FALSE.

It can look like this:
if ( TRUE ) {
/* Execute these statements if TRUE */
}
else {
/* Execute these statements if FALSE */
}

 

 


Array

An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched.