{"id":3696,"date":"2014-03-01T22:52:36","date_gmt":"2014-03-01T22:52:36","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=3696"},"modified":"2018-02-25T18:06:04","modified_gmt":"2018-02-25T18:06:04","slug":"computer-science-the-for-loop","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/computer-science-the-for-loop\/","title":{"rendered":"Computer Science:  the for loop"},"content":{"rendered":"<h1>Tutoring math &#8211; especially if you have a degree in it &#8211; you likely realize that some of your students are on their way to computer science courses.\u00a0 The math tutor opens the discussion on programming with the concept of the for loop.<\/h1>\n<p>Although computer programming offers separation from the machine that was unknown twenty years ago, the basic constructs of how a computer processes data are more relevant than ever.\u00a0 After all, more and more people are, undoubtedly, headed towards the field.<\/p>\n<p>A loop is a repeating operation that continues until some external condition is met.\u00a0 Alternatively, the loop may be infinite.<\/p>\n<p>The for loop is the type of loop that is often learned first in computer programming.\u00a0 Its basic structure:<\/p>\n<p><span style=\"font-size:130%;font-family:monospace\">for<\/span><\/p>\n<p>the number of times a counter variable remains less than the upper limit<\/p>\n<p><span style=\"font-size:130%;font-family:monospace\">perform<\/span><\/p>\n<p>these instructions<br \/>\nincrease the counter<\/p>\n<p><span style=\"font-size:130%;font-family:monospace\">back to for<\/span><\/p>\n<p>Giving a real example of a for loop, the immediate question is which language to use.  Imagine a space traveller arrived on earth and asked how to say &#8220;Hello&#8221;.  You&#8217;d tell them &#8220;Hello&#8221; in your own language; there isn&#8217;t a universal way to say it.<\/p>\n<p>Computer science offers the added complication that preferred languages change.  Someone &#8220;in the know&#8221; might well ask, <em>Why did you show it in that language?<\/em><\/p>\n<p>The language I&#8217;m introducing the for loop in is perl.  Known as &#8220;the duct tape of the internet,&#8221; it was critical in the early web boom.  Now it has competition from some languages purported to be easier to use.  Perl is famously powerful and well-loved by its own programmers.  It was developed by Larry Wall in 1987.  The name is an acronym:  Practical Extraction and Reporting Language.<\/p>\n<p>Here is a perl for loop:<\/p>\n<p><span style=\"color:#440000;font-family:monospace\">for(\\$i=0;\\$i<3;\\$i++){<\/span><\/p>\n<p><span style=\"color:#440000;font-family:monospace\">print &#8220;The counter is now at $i.\\n&#8221;;<\/span><\/p>\n<p><span style=\"color:#440000;font-family:monospace\">}<\/span><\/p>\n<p>The above loop outputs the following:<\/p>\n<p>The counter is now at 0.<br \/>\nThe counter is now at 1.<br \/>\nThe counter is now at 2.<\/p>\n<p>For a detailed explanation of how the code above produces that output, please return soon.  I&#8217;ll also discuss how to start experimenting with perl yourself, should you catch the bug:)<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tutoring math &#8211; especially if you have a degree in it &#8211; you likely realize that some of your students are on their way to computer science courses.\u00a0 The math tutor opens the discussion on programming with the concept of &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/computer-science-the-for-loop\/\"> <span class=\"screen-reader-text\">Computer Science:  the for loop<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[103,104],"class_list":["post-3696","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-for-loop","tag-perl"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/3696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=3696"}],"version-history":[{"count":56,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/3696\/revisions"}],"predecessor-version":[{"id":30489,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/3696\/revisions\/30489"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=3696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=3696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=3696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}