Bool in objective-C

Source: Internet
Author: User

In objc. H, bool is defined:

Typedef signed Char bool; # define Yes (bool) 1 # define no (bool) 0

From the preceding definition, we find that the value of the Boolean variable is YES/NO, or 1/0. Yes or 1 indicates true, and no or 0 indicates false. For example, you have defined a Boolean variable and assigned a value:

Bool enabled = no; Enabled = 0;

Determine whether the bool value is yes:

If (Enabled = Yes ){}

Or yes can be omitted

If (Enabled ){}

Determine whether the bool value is no:

If (! Enabled ){}

Or

If (enabled! = Yes ){}

Example:

Determines whether a number is a prime number. If yes, yes is returned. If not, no is returned.

-(Bool) isprime :( int num) {// The reader can think about the algorithm by himself. If you do not understand what needs to be explained, please leave a message for (INT I = 2; I <num/2; I ++) {If (Num % I = 0) {return no ;}} return yes ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.