{"id":37498,"date":"2016-07-10T18:15:34","date_gmt":"2016-07-10T12:45:34","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=37498"},"modified":"2016-07-20T12:56:54","modified_gmt":"2016-07-20T07:26:54","slug":"swift-for-loops","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/swift-for-loops\/","title":{"rendered":"Swift For-Loops"},"content":{"rendered":"<p>In Swift 3.0 C-style for-loops will be removed. This will force <a title=\"iOS app developers\" href=\"http:\/\/www.tothenew.com\/mobile-ios-application-development-services\">developers<\/a> to use a swift syntax for for-loops. So lets begin with swift for loops :<\/p>\n<ul>\n<li>Looping n times<\/li>\n<\/ul>\n<p>[code language=&#8221;objc&#8221;]<br \/>\n\/\/ output is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9<br \/>\nfor i in 0..&lt;10 {<br \/>\n\tprint(i)<br \/>\n}<br \/>\n\/\/ or<br \/>\nfor i in 0&#8230;9 {<br \/>\n\tprint(i)<br \/>\n}<br \/>\n[\/code]<\/p>\n<ul>\n<li>Looping n times in reverse<\/li>\n<\/ul>\n<p>[code language=&#8221;objc&#8221;]<br \/>\n\/\/ output is 10, 9, 8, 7, 6, 5, 4, 3, 2, 1<br \/>\nfor i in (1&#8230;10).reverse() {<br \/>\n    print(i)<br \/>\n}<br \/>\n[\/code]<\/p>\n<ul>\n<li>Looping through Array Values<\/li>\n<\/ul>\n<p>[code language=&#8221;objc&#8221;]<br \/>\n\/\/ output is: ashu, amit, deepak<br \/>\nlet namesArray = [&quot;ashu&quot;, &quot;amit&quot;, &quot;deepak&quot;]<br \/>\nfor name in namesArray {<br \/>\n    print(name)<br \/>\n}<br \/>\n[\/code]<\/p>\n<ul>\n<li>Looping through Dictionary Values<\/li>\n<\/ul>\n<p>[code language=&#8221;objc&#8221;]<br \/>\n\/\/ output is key is age &amp; value is 24, key is profession &amp; value is software development, key is name &amp; value is ashu<br \/>\nlet infoDict = [&quot;name&quot;: &quot;ashu&quot;, &quot;age&quot;: &quot;24&quot;, &quot;profession&amp;quot&quot;: &quot;software development&quot;]<br \/>\nfor (key,value) in infoDict {<br \/>\n\tprint(&quot;key is \\(key) &amp; value is \\(value)&quot;)<br \/>\n}<br \/>\n[\/code]<\/p>\n<ul>\n<li>Looping Through an Array with Index<\/li>\n<\/ul>\n<p>[code language=&#8221;objc&#8221;]<br \/>\n\/\/ output is index: 0 &amp; value: ashu, index: 1 &amp; value: amit, index: 2 &amp; value: deepak<br \/>\nlet namesArray = [&quot;ashu&quot;, &quot;amit&quot;, &quot;deepak&quot;]<br \/>\nfor (index,name) in namesArray.enumerate() {<br \/>\n\tprint(&quot;index: \\(index) &amp; value: \\(name)&quot;)<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>Congratulations! you have learned Swift for-loops!!!!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Swift 3.0 C-style for-loops will be removed. This will force developers to use a swift syntax for for-loops. So lets begin with swift for loops : Looping n times [code language=&#8221;objc&#8221;] \/\/ output is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 for i in 0..&lt;10 { print(i) } \/\/ or for [&hellip;]<\/p>\n","protected":false},"author":172,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[1400,1772,1],"tags":[3723,3726,3730,3724,3727,3725,3728,4848,3729,2715,3722,3721],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/37498"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/172"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=37498"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/37498\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=37498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=37498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=37498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}