{"id":865,"date":"2017-09-23T14:47:02","date_gmt":"2017-09-23T14:47:02","guid":{"rendered":"http:\/\/people.utm.my\/kohmenghock\/?page_id=865"},"modified":"2017-09-23T14:47:02","modified_gmt":"2017-09-23T14:47:02","slug":"codeblocks-simple-guide-repetitive-calculations-using-do-loop","status":"publish","type":"page","link":"https:\/\/people.utm.my\/kohmenghock\/codeblocks-simple-guide-repetitive-calculations-using-do-loop\/","title":{"rendered":"Code::Blocks simple guide &#8211; Repetitive calculations using do-loop"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nIn certain cases we might want to create a code to perform a repetitive calculation i.e. to perform same set of calculations many times. This can be done using <strong>do-loop<\/strong> in Fortran. The structure of a do-loop looks like the following.<br \/>\n<\/span><\/p>\n<p><a href=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_structure.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-867 size-full\" src=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_structure.png\" alt=\"\" width=\"707\" height=\"131\" srcset=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_structure.png 707w, https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_structure-300x56.png 300w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/a><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nLet us take an example whereby we want to generate the position of an object, with a fixed increment in position and for a certain amount of times depending on the input given by user. Assuming that we just need to know the position of the object at the end of the iterative process, then we do not need to record the position of the object at each iteration. If the converse is true, then one needs to make use of <strong>arrays<\/strong> to store the information. This will be covered later. For now, it is suffice to just print the value of the position at each iteration on the terminal.\u00a0<a href=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_position.png\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-868 size-full\" src=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_position.png\" alt=\"\" width=\"614\" height=\"244\" srcset=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_position.png 614w, https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_position-300x119.png 300w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/a><br \/>\n<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nIn the example given above, the position &#8221; x &#8221; will be increased by a value of &#8221; delta_x &#8221; for a total of &#8221; ite_max &#8221; times. The results appearing on the terminal is shown below.<br \/>\n<\/span><\/p>\n<p><a href=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_results.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-870 size-full\" src=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_results.png\" alt=\"\" width=\"397\" height=\"475\" srcset=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_results.png 397w, https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_results-251x300.png 251w\" sizes=\"auto, (max-width: 397px) 100vw, 397px\" \/><\/a><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nThe full code for the example above can be found <a href=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/main_code_do_loop.pdf\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nInstead of an incremental loop, one may also opt for a decremental one by changing the first line of the do-loop such as:<br \/>\n<\/span><\/p>\n<p><a href=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_decrement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-874 size-full aligncenter\" src=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_decrement.png\" alt=\"\" width=\"603\" height=\"263\" srcset=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_decrement.png 603w, https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_decrement-300x131.png 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/a><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nThe output for the decremental do-loop will be:<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"> <a href=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_results_decremental.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-875 size-full\" src=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_results_decremental.png\" alt=\"\" width=\"401\" height=\"379\" srcset=\"https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_results_decremental.png 401w, https:\/\/people.utm.my\/kohmenghock\/wp-content\/uploads\/sites\/982\/2017\/09\/do_loop_results_decremental-300x284.png 300w\" sizes=\"auto, (max-width: 401px) 100vw, 401px\" \/><\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; In certain cases we might want to create a code to perform a repetitive calculation i.e. to perform same set of calculations many times. This can be done using do-loop in Fortran. The structure of a do-loop looks like the following. Let us take an example whereby we want to generate the position of &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/people.utm.my\/kohmenghock\/codeblocks-simple-guide-repetitive-calculations-using-do-loop\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Code::Blocks simple guide &#8211; Repetitive calculations using do-loop&#8221;<\/span><\/a><\/p>\n","protected":false},"author":14180,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-865","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/pages\/865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/users\/14180"}],"replies":[{"embeddable":true,"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/comments?post=865"}],"version-history":[{"count":0,"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/pages\/865\/revisions"}],"wp:attachment":[{"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/media?parent=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}