Object-C 基础学习笔记(for,foreach,while,switch)

int main(int argc, const char * argv[]) {
    //for,foreach,while,do-while,switch
    
    NSMutableArray* mutableArray = [NSMutableArray arrayWithCapacity:2];
    
    [mutableArray addObject:@"item1"];
    [mutableArray addObject:@"item2"];
    [mutableArray addObject:@"item3"];
    
    NSLog(@"-------------------for---------------------");
    for(NSUInteger i=0;i<[mutableArray count];i++)
    {
        NSLog(@"%@",[mutableArray objectAtIndex:i]);
    }
    
    
    NSLog(@"-------------------foreach---------------------");
    
    for (id item in mutableArray) {
        NSLog(@"%@",item);
    }
    
    NSLog(@"-------------------while---------------------");
    
    NSUInteger count = 0;
    while (count < [mutableArray count]) {
        NSLog(@"%@",[mutableArray objectAtIndex:count]);
        count++;
    }
    
    NSLog(@"-------------------do-while---------------------");
    count = 0;
    do{
        NSLog(@"%@",[mutableArray objectAtIndex:count]);
        count++;
    }while (count<[mutableArray count]);
    
    NSLog(@"-------------------switch---------------------");
    int expression=4;
    switch (expression) {
        case 1:
            NSLog(@"expression=1");
            break;
        case 2:
            NSLog(@"expression=2");
            break;
        default:
            NSLog(@"expression=default");
            break;
    }
    
    return 0;
}

posted @ 2015-03-04 16:21  mfrbuaa  阅读(165)  评论(0编辑  收藏  举报