Possible Duplicate:
Help on Objective-C BOOL methods?
@interface
BOOL isCarryingmallet;
@implementation
-(BOOL)isCarryingWeapon {
return isCarryingMallet;
}
-(int)getWeaponDamage {
if (isCarryingMallet)
return kVikingMalletDamage;
else
return kVikingFistDamage;
}
I know that the -(BOOL)isCarryingWeapon returns isCarryingWeapon, but I don’t know why that’s useful. Can someone give me an example of it?
Also, what does continue;do in an if statement?
Thanks you!
Well
-(BOOL)isCarryingWeaponactually returns a bool. The type a method returns is whats specified in the brackets. e.g.(void)is nothing(NSString)would be a string.-(BOOL)isCarryingWeapon {return isCarryingMallet;
}
actually returns the value of isCarryingMallet. So calling
[myObject isCarryingWeapon]would give you a YES or NO based on the value ofisCarryingMallet.Continue is used in loops for example
continue means continue the loop on the next item from the start of the loop. break means stop looping. So you could use these in searching loops. If the item is not what you want you can continue to loop, if you find the item you want you could break ending the looping cycle early.