Traversal of an array

Source: Internet
Author: User

        //1. Iterating through an array with A for loopNsarray * array = @[@" One",@" Both",@"three"];  for(inti =0; i < Array.count; i++) {NSString* str =Array[i]; NSLog (@"array[%d] =%@", I,STR); }                //1. Data type//BOOL ID nsobject * (nsstring * nsarray *) block SEL//2. Process Control Statements//Enhanced for Loop        /*For (NSObject * obj in array) {}*/        //What is the value of your array.count, how many times he loops, and every time you take out an element in the data//stored in STR//2. Iterating through an array using the enhanced for loop method         for(NSString * STRinchArray) {NSLog (@"str =%@", str); }                        //3. Precautions//If you have a variety of different types of data in your array, it's best not to invoke an object-specific method that will cause the program to crash//in real-world development, an array is often responsible for storing only one type of dataPerson * P1 =[[Person alloc] init]; Nsarray* Array2 = @[@" One", [NSNumber Numberwithint:Ten],P1];  for(NSString * STRincharray2) {//NSLog (@ "array2 str%@", str);//NSLog (@ "str%ld", str.length);        }                //3. EnumeratorsNsarray * Array3 = @[@" One",@" Both",@"three"]; Nsenumerator* Enumerateor =[Array3 Objectenumerator]; NSString*value;  while(Value =[Enumerateor Nextobject]) {NSLog (@"enum STR%@", value); }        

Traversal of an array

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.