Objective-C Loops

来源:https://www.cnblogs.com/xujinzhong/archive/2018/02/09/8436362.html
-Advertisement-
Play Games

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 firs ...


  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 TypeDescription
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 TypeDescription
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 0;
}

  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.


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 高級查詢 關鍵字書寫順序 關鍵字執行順序select:投影結果 1 5 from:定位到表 2 1 where:分組前第一道過濾 3 2 group by:分組 4 3 having:分組後第二道過濾 5 4 order by:排序 6 6 limit: 最後 分頁 *目的:為了加快網站對數據的查詢 ...
  • MySQL 組複製實現了基於複製協議的多主更新(單主模式)。 複製組由多個 server成員構成,並且組中的每個 server 成員可以獨立地執行事務。但所有讀寫(RW)事務只有在衝突檢測成功後才會提交。只讀(RO)事務不需要在衝突檢測,可以立即提交。 對於任何 RW 事務,提交操作並不是由始發 s ...
  • 結構語言分類 DDL(數據定義語言) create drop alter 創建刪除以及修改資料庫,表,存儲過程,觸發器,索引.... DML(數據操作語言) insert delete update 用來操作資料庫中的數據 DQL(數據查詢語言) select 用來查詢資料庫中的數據 DCL(數據控 ...
  • 背景 原文地址(http://www.cnblogs.com/wenBlog/p/8435229.html) 最近針對我們的處理器出現了一系列的嚴重的bug。這種bug導致了兩個情況,就是熔斷和幽靈。 這就是這幾天鬧得人心惶惶的CPU大Bug。消息顯示,以英特爾處理器為代表的現代CPU中,存在可以導 ...
  • http://dcx.sybase.com/1101/en/dbprogramming_en11/ianywhere-data-sqlanywhere-saconnection-getschem6330755502-0.html http://razorsql.com/articles/sybase ...
  • 一、概述 mongodb是最接近關係型資料庫的NOSQL資料庫,它的存儲方式非常的靈活;以至於你會將它看成是一個經過冗餘過的關係型資料庫的表,這也是Mongodb原子性的一個特征。由於沒有關係型資料庫的表之間的關聯關係和事務性所以Mongodb插入和更新的效率非常的高,同時也支持索引。我們在查詢的時 ...
  • ViewPager中切換界面Fragment被銷毀的問題分析 使用ViewPager+Fragment實現界面切換,當界面數量大於3時,出現二次滑動後數據消失的情況,下麵由Fragment生命周期進行分析 簡單解析: 使用pager=3進行測試,當界面由2切換到1的時候,3界面對應的Fragment ...
  • 今天同事誤上傳一個庫,然後又刪除了。。。 我剛好把他上傳的庫給down下來了。。。然後項目一直報錯,clean。。。重新編譯。。。刪build文件。。。。全都不管用 好幾個人研究了好久,只能猜測是緩存問題。。。把項目的緩存全刪了沒用。。。。那應該是gradle緩存的問題。。。 可以我電腦上的grad ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...