{"id":3671,"date":"2024-02-19T11:35:51","date_gmt":"2024-02-19T10:35:51","guid":{"rendered":"https:\/\/oopm.org\/?page_id=3671"},"modified":"2024-11-27T10:03:37","modified_gmt":"2024-11-27T09:03:37","slug":"9-2-control-abstractions","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=3671","title":{"rendered":"9 Control structure methods"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages3671&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages3671&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">As mentioned in section <script>mkRef(\"Statements\")<\/script>, the term <em>control structure<\/em> is used for statements that control the order of execution of other statements. These include conditional statements, loop statements and break statements<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our programming language has some predefined control structures like <code>leave<\/code>, <code>restart<\/code>, <code>if:then<\/code>, <code>if:then:else<\/code>, <code>for:to:repeat<\/code> and <code>cycle<\/code> as used in the previous chapters. <code>Leave<\/code> and <code>restart<\/code> are examples of break statements; <code>if:then<\/code> and <code>if:then:else<\/code> are examples of conditional statements; and <code>cycle<\/code> and <code>for:to:repeat<\/code> are examples of loop statements. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The control structures <code>leave<\/code>, <code>restart<\/code>, and <code>if:then<\/code> are primitives (built-in) of qBeta. The other control structures are defined by means of methods. A method defining a control structure is called a <em>control structure method<\/em> or just <em>control method<\/em> for short. A control structure method represents an abstraction<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\"> <\/mark>over all the specific activities<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\"> <\/mark>like a method and class and is thus also referred to as a <em>control abstraction<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a first simple example of a control method, we will show how to define the <code>cycle<\/code>-statement as used in previous sections like in the example below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cycle\n   if (today.isFirstDayOfQuarter) :then\n      JohnSmithsAccount.addInterest\n      ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here <code>cycle<\/code> is a method used as a super method of a<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-2-color\"> <\/mark><em>singular method object<\/em> &#8211; singular method objects are described below. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We define <code>cycle<\/code> in the following way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cycle:\n   inner(cycle)\n   restart(cycle)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Execution of <code>cycle<\/code> implies that <code>inner(cycle)<\/code> is executed repeatedly. Execution of <code>inner(cycle)<\/code> implies that the statements in a possible submethod of <code>cycle<\/code> are executed. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For the above example this implies that the statement:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   if (today.isFirstDayOfQuarter) :then\n      JohnSmithsAccount.addInterest\n      ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">is executed forever unless a <code>leave<\/code>&#8211; or <code>restart<\/code> is executed within <code>...<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Singular method objects<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A statement of the form:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cycle\n   if (today.isFirstDayOfQuarter) :then\n      JohnSmithsAccount.addInterest\n      ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">is actually an object descriptor <em>derived<\/em> from cycle, describing an invocation of a singular method object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have seen example of singular objects described using <strong><code>obj<\/code><\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>account_1010: <strong>obj<\/strong>\n   owner: <strong>val<\/strong> \"John Smith\"\n   balance: <strong>var<\/strong> float<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As said in section <script>mkRef(\"The second program\");<\/script>, a singular object is a description of one specific object. It is not an instance of a class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We may actually declare a similar singular <em>object<\/em> using <code>cycle<\/code> as follows<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>doIt: <strong>obj<\/strong> cycle\n   if (today.isFirstDayOfQuarter) :then\n      JohnSmithsAccount.addInterest\n      ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, in most cases we will just use <code>cycle<\/code> as a statement and the statement:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cycle\n   if (today.isFirstDayOfQuarter) :then\n      JohnSmithsAccount.addInterest\n      ...<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">is as mentioned a description of an invocation of a singular method object like <code>doIt<\/code> declared using <strong><code>obj<\/code><\/strong>. The differences are that as a statement the singular method object has no name; the <code>doIt<\/code> object is generated and executed as part of the enclosing object whereas the singular method object is generated and executed as a statement.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"770\" height=\"346\" src=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/CycleSingularMethodDescriptor.jpg\" alt=\"\" class=\"wp-image-7558\" srcset=\"https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/CycleSingularMethodDescriptor.jpg 770w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/CycleSingularMethodDescriptor-300x135.jpg 300w, https:\/\/oopm.org\/wp-content\/uploads\/2024\/09\/CycleSingularMethodDescriptor-768x345.jpg 768w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><figcaption class=\"wp-element-caption\">CycleSingularMethodDescriptor<\/figcaption><\/figure>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=3671\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>As mentioned in section , the term control structure is used for statements that control the order of execution of other statements. These include conditional statements, loop statements and break statements Our programming language has some predefined control structures like leave, restart, if:then, if:then:else, for:to:repeat and cycle as used in the previous chapters. Leave and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":21,"menu_order":9,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3671","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/3671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3671"}],"version-history":[{"count":82,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/3671\/revisions"}],"predecessor-version":[{"id":9918,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/3671\/revisions\/9918"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/21"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}