Object-C,循环语句for,while,do-while
2015-11-29 14:31
495 查看
演示循环语句,for,while,do-while,和C系列的语言,语法基本一致1到10,求和
// // main.m // for-while // // Created by fansunion on 15/11/29. // Copyright (c) 2015年 demo. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { //for循环 int number = 10; int sum =0; //int n = 0; 也可以在上面定义int变量n for(int n=1;n<=number;n++){ sum += n; } NSLog(@"The sum is %i",sum); //while循环 int n2 = 1; int sum2 = 0; while(n2 <= 10){ sum2 += n2; n2++; } NSLog(@"The sum2 is %i",sum2); //do-while循环 int n3=1; int sum3=0; do{ sum3 += n3; n3++; }while(n3<=10); NSLog(@"The sum3 is %i",sum3); } return 0; }程序输出2015-11-29 14:25:08.975 for-while[2983:192052] The sum is 552015-11-29 14:25:08.977 for-while[2983:192052] The sum2 is 552015-11-29 14:25:08.978 for-while[2983:192052] The sum3 is 55Program ended with exit code: 0
相关文章推荐
- Object-C,循环语句for,while,do-while
- Object-C,循环语句for,while,do-while
- Objective-C:swift、objective-c、C++、C混合编程
- RegAsm注册DLL组件使用jacob调用的问题com.jacob.com.ComFailException: Can't co-create object
- (一)Course Learning Objectives【The Arduino Platform and C Pro】
- Object-C,文件路径API
- Object-C,文件路径API
- Object-C,文件路径API
- 从今天开始学习ios,入门第一天(Object-C学习笔记)自动引用计数和为类添加属性
- Object-C,遍历目录
- Object-C,遍历目录
- Object-C,遍历目录
- object-c之时间选择器UIDatePicker和UIpickerview筛选器
- object-c之时间选择器UIDatePicker和UIpickerview筛选器
- object-c之UItableView下拉刷新
- object-c之UItableView下拉刷新
- Objective-C学习 - KVO
- objc_setAssociatedObject 1
- objc_setAssociatedObject
- 【转载】html中object标签详解