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++类对象之间的类型转换和重载

    类对象和其他类型对象的转换 转换场合有: 赋值转换 表达式中的转换 显式转换 函数调用, 传递参数时的转换 转换方向有: 由定义类向其他类型的转换 由其他类型向定义类的转换 #include < ...

  2. Cube 数据 与 DW 数据对应不上

    场景: 时间维度表:字段(日期) 收费事实表:字段(金额,收费日期,就诊编号) 管理:使用维度表的 日期字段与事实表的 收费日期字段 进行关联,建立多维度数据集. 问题:     DW :   9月份 ...

  3. Alien Flowers

    题意: 求含有A个"RR",B个"RB",C个"BB",D个"BR"的字符串个数. 解法: 首先考虑"BR&q ...

  4. javamail - 发件、收件(SSL连接)

    需要的包:mail.jar  jsse.jar(说明:jsse.jar是jre自带的,如果jdk1.5及以下需要Java Activation Framework框架的activation.jar) ...

  5. 【Hadoop】HDFS笔记(一):Hadoop的RPC机制

    RPC(Remote Procedure Call, 远程过程调用)主要面对两个问题: 1.对象调用方式: 2.序列/反序列化机制. Hadoop实现的RPC组件依赖于Hadoop Writable类 ...

  6. 洛谷 - P3033 - 牛的障碍Cow Steeplechase - 二分图最大独立集

    https://www.luogu.org/fe/problem/P3033 二分图最大独立集 注意输入的时候控制x1,y1,x2,y2的相对大小. #include<bits/stdc++.h ...

  7. CSS Unicode字体

    在 CSS 中设置字体名称,直接写中文是可以的.但是在文件编码(GB2312.UTF-8 等)不匹配时会产生乱码的错误.xp 系统不支持 类似微软雅黑的中文. 方案一: 你可以使用英文来替代. 比如 ...

  8. 无法打开编译器生成的文件:“../../build/vs71/release/v100/MD_MBCS\json_value.

    1>正在生成代码 1>e:\Source\VC\?\json\jsoncpp-src-0.6.0-rc2\src\lib_json\json_value.cpp : fatal error ...

  9. HDU4247【瞎搞】

    题意: 给你4个小正方形的边长,让你求一个最小大正方形的边长以至于可以存这么四个正方形. 思路: 比划了一下...就是最大边+次大边,因为他们一定有交集. #include <cstdio> ...

  10. bzoj 2406: 矩阵【二分+有源汇上下界可行流】

    最大值最小,所以考虑二分 |Σaij-Σbij|<=mid,所以Σbij的上下界就是(Σaij-mid,Σaij+mid) 考虑建有上下界网络,连接(s,i,Σaik-mid,Σaik+mid) ...