{"id":38249,"date":"2016-10-24T09:45:14","date_gmt":"2016-10-24T14:45:14","guid":{"rendered":"http:\/\/hectormtzblog.wordpress.com\/?p=509"},"modified":"2016-10-24T09:45:14","modified_gmt":"2016-10-24T14:45:14","slug":"for-loop-2","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/for-loop-2\/","title":{"rendered":"For loop"},"content":{"rendered":"<p class=\"syndicated-attribution\"><em> --Originally published at <a href=\"https:\/\/hectormtzblog.wordpress.com\/2016\/10\/24\/for-loop\/\"><a href=\"https:\/\/hectormtzblog.wordpress.com\">Hector Martinez Alcantara<\/a><\/a><\/em><br \/><\/p>\n<p>Hi, I&#8217;m writing this post about the control flow tool called<em><strong> for<\/strong><\/em> loop. It&#8217;s used to repeat an action many times, but not only that, you can make a loop with specific conditions, and use it as a &#8216;foreach&#8217; in C.<\/p>\n<p>Another tool that we&#8217;re going to use is the range funtion that returns a list of a range of numbers.<\/p>\n<p>I&#8217;m going to explain how the different uses\u00a0of this\u00a0for loop works.<\/p>\n<p>First the sintaxis of the <em><strong>range<\/strong> <\/em>tool:<\/p>\n<pre>range('initial number','last number range','conditional number')<\/pre>\n<p>Examples of use of range function:<\/p>\n<pre>#It can be used only as a quantity of numbers\nrange(5)\n#The result is a list of numbers between 0 and 5 = [0,1,2,3,4]\n\n#Used as a range of numbers\nrange(4,14)\n#The result is a list of the range of numbers between 4 and 14 = [4,5,6,7,8,9,10,11,12,13]\n\n#Used as a range of numbers with a jump condition\nrange(0,100,10)\n#The result is a list of the range between 0 and 100 every 10 numbers = [0,10,20,30,40,50,60,70,80,90]<\/pre>\n<p>Now the sintaxis of the for tool:<\/p>\n<pre>for 'variable' in 'list' :\n     #conditions<\/pre>\n<p>Examples of for loop function:<\/p>\n<pre>#Doing a quantity of actions\nfor number in range(8):\n    print(\"Hello\")\n#The result is a print of the word 'Hello' 8 times\n\n#Using a range of numbers\nfor number in range(10,20):\n    print(number)\n#The result is a print of numbers from 10 to 19\n\n#Using a range of numbers with a special jump condition\nfor number in range(0,10,2):\n    print(number)\n#The result is the pair numbers from 0 to 8\n\n#Using a variable\nword=\"Hello\"\nfor letter in word:\n    print(letter)\n#The result is a print of every letter in the word 'Hello' = ['H','e','l','l','o']<\/pre>\n<p>The explanation is that the <em><strong>for<\/strong> <\/em>function takes every component in a list of components and use the component as the variable, for each component, the actions <div class=\"post-limited-image\"><img src=\"https:\/\/31.media.tumblr.com\/a001d4594a4af838fdc30068d4d6e9fd\/tumblr_inline_nlc7dnCeSV1qf17wq.gif\" \/><\/div>\n<div class=\"post-limited-image\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/hectormtzblog.wordpress.com\/509\/\" \/><\/div>\n<div class=\"post-limited-image\"><img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=hectormtzblog.wordpress.com&#038;blog=115238241&%23038;post=509&%23038;subd=hectormtzblog&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/><\/div><!--more--> the for function will be realized.<\/p>\n<p>Thank you for reading, any questions in comments.<\/p>\n<p>Special thanks to\u00a0<a href=\"https:\/\/docs.python.org\/3\/tutorial\/controlflow.html\" >The python documentation<\/a>.<\/p>\n<p><img src=\"https:\/\/31.media.tumblr.com\/a001d4594a4af838fdc30068d4d6e9fd\/tumblr_inline_nlc7dnCeSV1qf17wq.gif\" \/><\/p><br \/>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/hectormtzblog.wordpress.com\/509\/\"><img alt=\"\" border=\"0\" src=\"http:\/\/feeds.wordpress.com\/1.0\/comments\/hectormtzblog.wordpress.com\/509\/\" \/><\/a> <img alt=\"\" border=\"0\" src=\"https:\/\/pixel.wp.com\/b.gif?host=hectormtzblog.wordpress.com&#038;blog=115238241&%23038;post=509&%23038;subd=hectormtzblog&%23038;ref=&%23038;feed=1\" width=\"1\" height=\"1\" \/>","protected":false},"excerpt":{"rendered":"<p>&#8211;Originally published at Hector Martinez Alcantara Hi, I&#8217;m writing this post about the control flow tool called for loop. It&#8217;s used to repeat an action many times, but not only that, you can make a loop with specific conditions, and use it as a &#8216;foreach&#8217; in C. Another tool that we&#8217;re going to use is &hellip; <a href=\"https:\/\/kenscourses.com\/tc101fall2016\/syndicated\/for-loop-2\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">For loop<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":38250,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[88,89,44,26,33],"class_list":["post-38249","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-learninganewlanguage","tag-python3","tag-loops","tag-sin-categoria","tag-tc101"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/38249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/comments?post=38249"}],"version-history":[{"count":1,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/38249\/revisions"}],"predecessor-version":[{"id":38252,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/posts\/38249\/revisions\/38252"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/media\/38250"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/media?parent=38249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/categories?post=38249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101fall2016\/wp-json\/wp\/v2\/tags?post=38249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}