您的位置:首页 > 移动开发 > Objective-C

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

2015-03-04 16:21 399 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐