{"id":604,"date":"2025-07-21T09:42:51","date_gmt":"2025-07-21T09:42:51","guid":{"rendered":"https:\/\/tipcontrol.com\/?page_id=604"},"modified":"2025-07-21T09:42:51","modified_gmt":"2025-07-21T09:42:51","slug":"dowhile-statement","status":"publish","type":"page","link":"https:\/\/tipcontrol.com\/?page_id=604","title":{"rendered":"dowhile statement"},"content":{"rendered":"\n<p>The <code>dowhile<\/code> loop is a control structure in Tipcontrol and slightly different to languages, such as C++,it is used to execute a block of code at least once and then repeat the execution as long as a specified condition evaluates to true. This structure guarantees at least one iteration, as the condition is checked after the loop body is executed. The difference to C an similiar languages is that the condition is written at the top of the control block dowhile(\u2026) instead of after, even though the test is done after the execution.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Structure of a&nbsp;<code>do...while<\/code>&nbsp;Loop<\/h4>\n\n\n\n<p><strong>Components<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Condition<\/strong>: An expression evaluated aafter each iteration of the loop. If the condition evaluates to\u00a0<code>true<\/code>\u00a0(non-zero), the code block inside the loop is executed again. If it evaluates to\u00a0<code>false<\/code>\u00a0(zero), the loop terminates.<\/li>\n\n\n\n<li><strong>Code Block<\/strong>: The block of code that executes during each iteration while the condition is true. This block is enclosed in curly braces\u00a0<code>{}<\/code>.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Simple Example<\/h4>\n\n\n\n<p>&nbsp; &nbsp; counter = 1; \/\/ Initialization<\/p>\n\n\n\n<p>&nbsp; &nbsp; \/\/ Loop while counter is less than or equal to 5<\/p>\n\n\n\n<p>&nbsp; &nbsp; dowhile (counter &lt; 1) {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; lib.log(&#8220;Count: \u201c+ counter);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; counter+=1; \/\/ Update the counter<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p><strong>Explanation<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Initialization<\/strong>:\u00a0<code>counter = 1;<\/code>\u00a0initializes a counter variable.<\/li>\n\n\n\n<li><strong>Condition<\/strong>:\u00a0<code>counter &lt; 1<\/code>\u00a0checks if the counter is less than or equal to 1, the loop in the example will run once as the condition is only checked after the code block.\u00a0<\/li>\n\n\n\n<li><strong>Code Block<\/strong>: The statement\u00a0<code>lib.log(\u201cCount: \u201c + counter);<\/code>\u00a0is executed at least once, and then as long as the condition is true.<\/li>\n\n\n\n<li><strong>Update<\/strong>:\u00a0<code>counter+= 1<\/code>\u00a0increments the counter at the end of each iteration to eventually make the condition false and terminate the loop.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Practical Use<\/h3>\n\n\n\n<p>The <code>dowhile<\/code> loop is particularly useful when you need a loop to execute the code block at least once, regardless of whether the condition is initially true or false, for example reading values from a sensor or other operations that need an initial value.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The dowhile loop is a control structure in Tipcontrol and slightly different to languages, such as C++,it is used to execute a block of code at least once and then repeat the execution as long as a specified condition evaluates to true. This structure guarantees at least one iteration, as the condition is checked after [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-604","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=604"}],"version-history":[{"count":1,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/604\/revisions"}],"predecessor-version":[{"id":605,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/604\/revisions\/605"}],"wp:attachment":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}