{"id":3778,"date":"2020-09-06T22:07:24","date_gmt":"2020-09-06T13:07:24","guid":{"rendered":"https:\/\/katblog.manadream.net\/?p=3778"},"modified":"2020-10-11T22:06:16","modified_gmt":"2020-10-11T13:06:16","slug":"writing-loop-processes-for-statement","status":"publish","type":"post","link":"https:\/\/katblog.manadream.net\/index.php\/2020\/09\/06\/writing-loop-processes-for-statement\/","title":{"rendered":"[PHP]Let&#8217;s Try Writing Loop Processes! [for statement] [Programming for Kids and Above #7]"},"content":{"rendered":"<p>Hello!<\/p>\n<p>I&#8217;m kat, the manager of &#8216;kat&#8217;s blog&#8217;.<\/p>\n<p>This time, which is the seventh installment of the &#8216;Programming Lessons&#8217; series, I will be talking about <span class=\"marker\">loop<\/span> processing.<\/p>\n<p>In our daily lives, we do certain things <span class=\"marker\">over and over again<\/span>, right?<\/p>\n<p>For instance, when going to school, we take the same route at the same time everyday.<\/p>\n<p>It&#8217;s a <span class=\"marker2\">hassle to have to write out the same process<\/span> over and over again to do something repeatedly in programming.<\/p>\n<p>Actually, there is a way to write it out <span class=\"marker\">very easily<\/span>.<\/p>\n<p>Let&#8217;s learn how to do that this time!<\/p>\n\n\n<h2 class=\"wp-block-heading\">What we will use this time<\/h2>\n\n\n<p><div class=\"kaisetsu-box4\"><div class=\"kaisetsu-box4-title\">The programming language we will use this time<\/div><p><\/p>\n<p>This time we will use the following programming language to write out a program.<\/p>\n<div class=\"simple-box7\">\n<p>\u30fbPHP<\/p>\n<\/div>\n<p><\/p><\/div><\/p>\n<p><div class=\"kaisetsu-box4\"><div class=\"kaisetsu-box4-title\">The programming environment we will use this time<\/div><p><\/p>\n<p>Let&#8217;s use the paiza website which is listed below for executing the program.<\/p>\n<p><span class=\"twobutton\"><span class=\"color-button02\"><a href=\"https:\/\/paiza.io\/en\/projects\/new\" target=\"_blank\" rel=\"noopener noreferrer\">paiza website<\/a><\/span><\/span><\/p>\n<p>\u203bFor those who are using this for the first time, please check the page below. It gives instructions on how to use the website.<\/p>\n<p>https:\/\/katblog.manadream.net\/index.php\/2020\/06\/09\/how-to-use-paiza-io\/<\/p>\n<p><\/p><\/div><\/p>\n\n\n<h2 class=\"wp-block-heading\">What is loop processing?<\/h2>\n\n\n<p>As I said in the beginning, loop processing is to do the <span class=\"marker\">same thing over and over again<\/span> many times.<\/p>\n<p>In loop processing, the same process will be repeated for as many times as you choose.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3821\" data-permalink=\"https:\/\/katblog.manadream.net\/index.php\/2020\/09\/06\/writing-loop-processes-for-statement\/loop1_en\/\" data-orig-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/loop1_en.png\" data-orig-size=\"906,1084\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"loop1_en\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/loop1_en-251x300.png\" data-large-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/loop1_en-856x1024.png\" class=\"wp-image-3821 aligncenter\" src=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/loop1_en-856x1024.png\" alt=\"\" width=\"425\" height=\"509\"><\/p>\n<p>Once the first process is finished, the second process will start after it has returned to the beginning of the loop.<\/p>\n\n\n<h2 class=\"wp-block-heading\">Let&#8217;s write out a loop process<\/h2>\n\n\n<p>Now then, let&#8217;s actually write out a loop process.<\/p>\n<p>For this time, let&#8217;s make it so that to the numbers; 1,2,3,4,5,6,7,8,9, 2 will be added to each of them, and the numbers will be displayed in order.<\/p>\n<p>You can think of the process to go like this.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3822\" data-permalink=\"https:\/\/katblog.manadream.net\/index.php\/2020\/09\/06\/writing-loop-processes-for-statement\/loop2_en\/\" data-orig-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/loop2_en.png\" data-orig-size=\"906,1084\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"loop2_en\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/loop2_en-251x300.png\" data-large-file=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/loop2_en-856x1024.png\" class=\"wp-image-3822 aligncenter\" src=\"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/09\/loop2_en-856x1024.png\" alt=\"\" width=\"424\" height=\"507\"><\/p>\n<p>This will be repeated a total of <span class=\"marker\">nine times<\/span> from 1~ 9.<\/p>\n<p>Now, let&#8217;s take a look at the source code.<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n\/\/ Repeat for 1~9\nfor ($i = 1; $i &lt; 10; $i++) {\n  \/\/ Display after adding 2\n  $result = $i + 2;\n  echo $result . &quot;,&quot;;\n}\n<\/pre><\/div>\n\n<p>When this is executed,<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n3,4,5,6,7,8,9,10,11,\n<\/pre><\/div>\n\n<p>the result will be displayed as shown above.<\/p>\n<p>As you can see, 2 has been added to each number without fail.<\/p>\n<p><div class=\"kaisetsu-box3\"><div class=\"kaisetsu-box3-title\">\uff5eExplanation 1\uff5e<\/div><p><\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; first-line: 3; title: ; notranslate\" title=\"\">\n\/\/ Repeat for 1~9\nfor ($i = 1; $i &lt; 10; $i++) {\n<\/pre><\/div>\n\n<p>This is called a for statement, and is used when doing loop processing.<\/p>\n<p>The process that is written after the &#8216;{&#8216; of the for statement will be executed repeatedly.<\/p>\n<p>Also this time, the numbers from 1~9 will be in the &#8216;$i&#8217; variable. (<span class=\"marker\">The variable can be named freely<\/span>)<\/p>\n<p>&#8216;$i = 1;&#8217; which is within the &#8216;()&#8217; of the for statement, means that the numbers that are in &#8216;$i&#8217; start from 1.<\/p>\n<p>&#8216;$i &lt; 10;&#8217; means that the process will be repeated while &#8216;$i&#8217; is smaller than 10.<\/p>\n<p>The &#8216;$i++&#8217; at the end means that 1 will be added each time &#8216;$i&#8217; loops around.<\/p>\n<div class=\"kaisetsu-box4\"><div class=\"kaisetsu-box4-title\">\u2713 Point<\/div><p><\/p>\n<p>By changing the value in the &#8216;()&#8217; of the for statement, <span class=\"marker\">you can freely change the number of times the loop repeats<\/span>.<\/p>\n<p>&#8216;for ($i = 1; $i &lt; 366; $i++) {&#8216;<\/p>\n<p>By making it this way, we can make it repeat 365 times.<\/p>\n<p>The &#8216;&lt;&#8216; used in &#8216;$i &lt; 366;,&#8217; means &#8216;less than ~,&#8217; so the number that comes to the right of it needs to be 1 larger than the maximum number.<\/p>\n<p>However, if &#8216;&lt;=&#8217; is used, this means &#8216;less than or equal to ~,&#8217; so in that case there is no problem in making the maximum number &#8216;365.&#8217;<\/p>\n<p><\/p><\/div>\n<p><\/p><\/div><\/p>\n<p><div class=\"kaisetsu-box3\"><div class=\"kaisetsu-box3-title\">\uff5eExplanation 2\uff5e<\/div><p><\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; first-line: 5; title: ; notranslate\" title=\"\">\n    \/\/ Add 2 and display\n    $result = $i + 2;\n    echo $result . &quot;,&quot;;\n<\/pre><\/div>\n\n<p>This is a review of up until last time. The following process is being executing in order.<\/p>\n<div class=\"simple-box4\">\n<p>\u30fbAdd 2 to &#8216;$i,&#8217; and enter the result in &#8216;$result.&#8217;<\/p>\n<p>\u30fbOutput &#8216;$result&#8217; and &#8216;,&#8217; on the screen.<\/p>\n<\/div>\n<p><\/p><\/div><\/p>\n\n\n<h2 class=\"wp-block-heading\">Final thoughts<\/h2>\n\n\n<p>Thank you for reading to the end of this lesson this time as well.<\/p>\n<p>This time we learned about <span class=\"marker\">for statements<\/span> of loop processing, but I think you now understand how useful they are when you want to do multiple processes of the same kind.<\/p>\n<p>\u00a0<\/p>\n<p>I explained about loop processing this time as well, but this almost always comes up when doing programming, so please try to memorize it!<\/p>\n<p>See you next time!<\/p>\n\n\n<br>\n\n\n\n<div class=\"wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-button alignleft is-style-outline is-style-outline--4fd2cdf712ea231a88d031e4b1453c5a\"><a class=\"wp-block-button__link has-vivid-cyan-blue-color has-text-color\" href=\"https:\/\/katblog.manadream.net\/index.php\/2020\/09\/03\/connecting-letters\/\">&lt;&lt; Proceed to previous article<\/a><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<div class=\"wp-block-button alignright is-style-outline is-style-outline--764e082f5380489b1e247320e3d64c4f\"><a class=\"wp-block-button__link has-vivid-cyan-blue-color has-text-color\" href=\"https:\/\/katblog.manadream.net\/index.php\/2019\/08\/29\/child-programming-8\/\">Proceed to next article &gt;&gt;<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! I#8217;m kat, the manager of #8216;kat#8217;s blog#8217;. This time, which is the seventh installme<\/p>\n","protected":false},"author":1,"featured_media":4162,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_locale":"ja","_original_post":"https:\/\/katblog.manadream.net\/?p=3778","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[102],"tags":[107,108],"class_list":["post-3778","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-lessons","tag-english","tag-programming","ja"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2020\/10\/kurumaa.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paUgnN-YW","_links":{"self":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3778"}],"collection":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/comments?post=3778"}],"version-history":[{"count":45,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3778\/revisions"}],"predecessor-version":[{"id":4171,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/3778\/revisions\/4171"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media\/4162"}],"wp:attachment":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media?parent=3778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/categories?post=3778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/tags?post=3778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}