There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.

  Programming languages provide various control structures that allow for more complicated execution paths.

  A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages:

  Objective-C programming language provides the following types of loop to handle looping requirements. Click the following links to check their details.

Loop Type Description
while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.
for loop Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.
do...while loop Like a while statement, except that it tests the condition at the end of the loop body.
nested loops You can use one or more loops inside any another while, for or do..while loop.

Loop Control Statements:

  Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.

  Objective-C supports the following control statements. Click the following links to check their details.

Loop Type Description
while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.
for loop Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.
do...while loop Like a while statement, except that it tests the condition at the end of the loop body.
nested loops You can use one or more loops inside any another while, for or do..while loop.

The Infinite Loop:

  A loop becomes infinite loop if a condition never becomes false. The for loop is traditionally used for this purpose. Since none of the three expressions that form the for loop are required, you can make an endless loop by leaving the conditional expression empty.

#import <Foundation/Foundation.h>

int main ()
{
for( ; ; )
{
NSLog(@"This loop will run forever.\n");
} return ;
}

  When the conditional expression is absent, it is assumed to be true. You may have an initialization and increment expression, but Objective-C programmers more commonly use the for(;;) construct to signify an infinite loop.

Objective-C Loops的更多相关文章

  1. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

  2. Objective -C Categories

    Objective -C Categories  The dynamic runtime dispatch mechanism employed by Objective-C lets you add ...

  3. WWDC 上讲到的 Objective C / LLVM 改进

    https://developer.apple.com/wwdc/videos/ Advances in Objective-C What's New in the LLVM Compiler 下面是 ...

  4. Nested Loops join时显示no join predicate原因分析以及解决办法

    本文出处:http://www.cnblogs.com/wy123/p/6238844.html 最近遇到一个存储过程在某些特殊的情况下,效率极其低效, 至于底下到什么程度我现在都没有一个确切的数据, ...

  5. SQL Tuning 基础概述06 - 表的关联方式:Nested Loops Join,Merge Sort Join & Hash Join

    nested loops join(嵌套循环)   驱动表返回几条结果集,被驱动表访问多少次,有驱动顺序,无须排序,无任何限制. 驱动表限制条件有索引,被驱动表连接条件有索引. hints:use_n ...

  6. Objective C中的ARC的修饰符的使用---- 学习笔记九

    #import <Foundation/Foundation.h> @interface Test : NSObject /** * 默认的就是__strong,这里只是做示范,实际使用时 ...

  7. Objective的字符串拼接 似乎没有Swift方便,但也可以制做一些较为方便的写法

    NSString *str1 = @"字符串1"; NSString *str2 = @"字符串2"; //在同样条件下,Objective的字符串拼接 往往只 ...

  8. track message forwards, avoiding request loops, and identifying the protocol capabilities of all senders along the request/response chain

    https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html The TRACE method is used to invoke a remote, ...

  9. [转] 从 C 到 Objective C 入门1

    转自: http://blog.liuhongwei.cn/iphone/objective-c/ 进军iPhone开发,最大的难点之一就是怪异的Objective C语法了.不过,了解之后才发现,原 ...

  10. Objective C运行时(runtime)

    #import <objc/runtime.h> void setBeingRemoved(id __self, SEL _cmd) { NSLog(@"------------ ...

随机推荐

  1. C++之全局函数和成员函数互相转换

    解析:成员函数会用this指针自动隐藏第一个操作数(左操作数) 1.把全局函数转化成成员函数,通过this指针隐藏左操作数. Test add(Test &t1,Test &t2)  ...

  2. OpenResty创造者

    OpenResty 是一个开源的 Web 平台,用于开发高性能和高动态的 Web 网关或者 Web 应用.OpenResty 最早是为了支持全网搜索引擎周边的相关搜索的 API 接口,后来我们基于 N ...

  3. xen添加网卡

    brctl addbr xenbr0 ifconfig xenbr0 up ifconfig xenbr0 192.168.0.1 /etc/xen/scripts/network-bridge st ...

  4. HTML5/jQuery雷达动画图表 图表配置十分简单

    1.HTML5/jQuery雷达动画图表 图表配置十分简单 之前我们介绍过不少形形色色的HTML5图表了,像这款HTML5折线图表Aristochart是一款很不错的折线图表,这款HTML5 Canv ...

  5. 在windows64位的系统上面操作操作excel程序出现异常

    1.把iis的网站程序引用池启用32位设置 2.把iis的网站程序引用池启用中标识修改为LocalSystem 2.代开cmd 输入mmc -32 添加组件服务在dcom组件中找到excel安全里添加 ...

  6. 利用vs自带工具分析程序性能

    测试程序写好后可以通过VS2010分析菜单里选择启用性能向导 选择CPU采样后就选择需要分析的项目 测试项目选择完成后就可以运行分析,结束分析后VS2010会提供个详细报告文档 从分析结果来看GetC ...

  7. 为什么用思科里面的设备第一次ping的时候总会丢一个包呢?

    大家搞计算机的不用讲,肯定都玩过网络吧?   比如一些思科,华为,华三这些模拟器,你们总会当你第一次用某个设备去ping某个设备的时候第一包总会被丢弃.  但我相信很多人都不知道为啥 会丢弃. 今天小 ...

  8. UVa 1349 Optimal Bus Route Design (最佳完美匹配)

    题意:给定一个有向图,让你找出若干个图,使得每个点恰好属于一个圈,并且总的权和最小. 析:每个点都有唯一的一个圈,也就是说每一点都有唯一的后继,那么我们就可以转换成求一个图的最小权的最佳完全匹配,可以 ...

  9. SqlServer自定义数据类型

    定义:用户自己设计并实现的数据类型就称为用户自定义数据类型,即使这些数据类型基于系统数据类型. 创建用户自定义数据类型时,必须提供三个数: 数据类型的名称 所基于的系统数据类型 数据类型的可空性(是否 ...

  10. django使用QQ企业邮箱发送邮件

    一.首先申请QQ企业邮箱 免费QQ企业邮箱地址如下:https://exmail.qq.com/signupfree?refer=intro#signup/free 二.配置自己的域名 在域名解析中添 ...