{"id":213485,"date":"2025-05-11T04:05:15","date_gmt":"2025-05-11T04:05:15","guid":{"rendered":"https:\/\/learnexams.com\/blog\/?p=213485"},"modified":"2025-05-11T04:05:18","modified_gmt":"2025-05-11T04:05:18","slug":"the-body-of-a-do-while-loop-always-executes-at-least-once","status":"publish","type":"post","link":"https:\/\/www.learnexams.com\/blog\/2025\/05\/11\/the-body-of-a-do-while-loop-always-executes-at-least-once\/","title":{"rendered":"The Body Of A Do-While Loop Always Executes At Least Once"},"content":{"rendered":"\n<p>True Or False: 1) The Body Of A Do-While Loop Always Executes At Least Once. 2) The Body Of A While Loop May Never Execute. 3) The Opposite Of (X >3 &amp;&amp; X&lt; 10)=&#8221;&#8221; is=&#8221;&#8221; (x=&#8221;&#8221;>&lt; 3=&#8221;&#8221; &amp;&amp;=&#8221;&#8221; x=&#8221;&#8221;> 10) 4) The Integer 0 Is Considered True. 5) It Is Legal To Declare More Than One Variable In A Single Statement. 6) Variable Names May Begin With A Number. 7) The Opposite Of Less Than<\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">The Correct Answer and Explanation is:<\/mark><\/strong><\/p>\n\n\n\n<p>Let&#8217;s evaluate each of the 7 statements and determine whether they are <strong>True or False<\/strong>, followed by a detailed explanation.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 1) <strong>The body of a do-while loop always executes at least once.<\/strong><\/h3>\n\n\n\n<p><strong>\u2714\ufe0fTrue<\/strong><br><strong>Explanation:<\/strong><br>In a <strong>do-while<\/strong> loop, the syntax ensures that the loop body executes <strong>before<\/strong> the condition is checked. This guarantees that the block inside the <code>do<\/code> executes <strong>at least once<\/strong>, regardless of whether the condition is <code>true<\/code> or <code>false<\/code>.<br>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int i = 5;\ndo {\n   cout &lt;&lt; i;\n} while (i &lt; 3);  \/\/ Still prints 5 once even though i &lt; 3 is false\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 2) <strong>The body of a while loop may never execute.<\/strong><\/h3>\n\n\n\n<p><strong>\u2714\ufe0fTrue<\/strong><br><strong>Explanation:<\/strong><br>In a <strong>while loop<\/strong>, the condition is checked <strong>before<\/strong> the loop body executes. If the condition is initially false, the loop body is skipped entirely.<br>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int i = 5;\nwhile (i &lt; 3) {\n   cout &lt;&lt; i;\n}\n\/\/ Nothing prints because condition is false initially.\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 3) <strong>The opposite of (x &gt; 3 &amp;&amp; x &lt; 10) is (x &lt; 3 &amp;&amp; x &gt; 10).<\/strong><\/h3>\n\n\n\n<p><strong>\u274cFalse<\/strong><br><strong>Explanation:<\/strong><br>The opposite of a compound condition using <code>&amp;&amp;<\/code> is derived using <strong>De Morgan\u2019s Law<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The opposite of <code>(A &amp;&amp; B)<\/code> is <code>!A || !B<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>So:<br><code>!(x &gt; 3 &amp;&amp; x &lt; 10)<\/code> \u2192 <code>(x &lt;= 3 || x &gt;= 10)<\/code><br><strong>(x &lt; 3 &amp;&amp; x &gt; 10)<\/strong> is logically impossible (no number can be both less than 3 <strong>and<\/strong> greater than 10).<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 4) <strong>The integer 0 is considered true.<\/strong><\/h3>\n\n\n\n<p><strong>\u274cFalse<\/strong><br><strong>Explanation:<\/strong><br>In C, C++, and many other languages, <strong>0 is considered false<\/strong>, and <strong>any non-zero value is true<\/strong>. This is fundamental to how Boolean logic works in these languages.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 5) <strong>It is legal to declare more than one variable in a single statement.<\/strong><\/h3>\n\n\n\n<p><strong>\u2714\ufe0fTrue<\/strong><br><strong>Explanation:<\/strong><br>Yes, multiple variables can be declared in one line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a = 5, b = 10, c;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 6) <strong>Variable names may begin with a number.<\/strong><\/h3>\n\n\n\n<p><strong>\u274cFalse<\/strong><br><strong>Explanation:<\/strong><br>In most programming languages, variable names <strong>must not<\/strong> start with a digit. They must start with a letter (A-Z or a-z) or an underscore <code>_<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 7) <strong>The opposite of less than is greater than.<\/strong><\/h3>\n\n\n\n<p><strong>\u274cFalse<\/strong><br><strong>Explanation:<\/strong><br>The opposite of <strong>less than (<code>&lt;<\/code>)<\/strong> is <strong>greater than or equal to (<code>&gt;=<\/code>)<\/strong>, not just <strong>greater than (<code>&gt;<\/code>)<\/strong>.<br>Example:<br>If <code>x &lt; 5<\/code> is false, it means <code>x &gt;= 5<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Summary of Answers:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>True<\/li>\n\n\n\n<li>True<\/li>\n\n\n\n<li>False<\/li>\n\n\n\n<li>False<\/li>\n\n\n\n<li>True<\/li>\n\n\n\n<li>False<\/li>\n\n\n\n<li>False<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>True Or False: 1) The Body Of A Do-While Loop Always Executes At Least Once. 2) The Body Of A While Loop May Never Execute. 3) The Opposite Of (X >3 &amp;&amp; X&lt; 10)=&#8221;&#8221; is=&#8221;&#8221; (x=&#8221;&#8221;>&lt; 3=&#8221;&#8221; &amp;&amp;=&#8221;&#8221; x=&#8221;&#8221;> 10) 4) The Integer 0 Is Considered True. 5) It Is Legal To Declare More Than [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-213485","post","type-post","status-publish","format-standard","hentry","category-exams-certification"],"_links":{"self":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/213485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/comments?post=213485"}],"version-history":[{"count":0,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/213485\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/media?parent=213485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/categories?post=213485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/tags?post=213485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}