{"id":6567,"date":"2021-06-24T15:31:48","date_gmt":"2021-06-24T15:31:48","guid":{"rendered":"https:\/\/www.scmgalaxy.com\/tutorials\/?p=6567"},"modified":"2022-04-13T16:33:35","modified_gmt":"2022-04-13T16:33:35","slug":"what-is-loop-what-are-the-syntax","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/","title":{"rendered":"What is Loop What are the Syntax?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\" id=\"0fab\">In this turorial i\u2019m going to learn about Lools, how to use and how to write.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"0a31\">What is loop?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"1195\">A Loop is an Iterative Control Structure that involves executing the same number of code a whatever you write in the codition its used to execute the same block code again to again whenever its condition is false.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"01f6\">Syntax:-<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">while(condition){<br>    \/\/ Code to be executed<br>}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"1266\">EX:-<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?php    <br>for($n=1;$n&lt;=10;$n++){    <br>echo \"$n&lt;br\/&gt;\";    <br>}    <br>?&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"982f\"><strong>Result:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"b115\"><strong>When to use while loops<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>While loops are used to execute a block of code until a certain condition becomes true.<\/li><li>You can use a while loop to read records returned from a database query.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"663c\"><strong>Types of while loops<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Do\u2026 while<\/strong>&nbsp;\u2014 executes the block of code at least once before evaluating the condition<\/li><li><strong>While\u2026<\/strong>&nbsp;\u2014 checks the condition first. If it evaluates to true, the block of code is executed as long as the condition is true. If it evaluates to false, the execution of the while loop is terminated.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"ce1b\">The Do while loop is similar to&nbsp;the while loop with one important difference. The body of do while loop is executed at least once. Only then, the test expression is excuted.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">do<br>{<br>   \/\/ the body of the loop<br>}<br>while (testExpression);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"7468\">Exmple: &#8211;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?php<br>$x = 1;<br><br>do {<br>  echo \"The number is: $x &lt;br&gt;\";<br>  $x++;<br>} while ($x &lt;= 5);<br>?&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"f0f1\">Outputs:-<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">The number is: 1<br>The number is: 2<br>The number is: 3<br>The number is: 4<br>The number is: 5<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this turorial i\u2019m going to learn about Lools, how to use and how to write. What is loop? A [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5388],"tags":[5401,177,5208,5407],"class_list":["post-6567","post","type-post","status-publish","format-standard","hentry","category-php","tag-loop","tag-php","tag-php-framework","tag-phpsyntax"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is Loop What are the Syntax? - scmGalaxy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Loop What are the Syntax? - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"In this turorial i\u2019m going to learn about Lools, how to use and how to write. What is loop? A [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-24T15:31:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-13T16:33:35+00:00\" \/>\n<meta name=\"author\" content=\"rajeshkumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rajeshkumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/\"},\"author\":{\"name\":\"rajeshkumar\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\"},\"headline\":\"What is Loop What are the Syntax?\",\"datePublished\":\"2021-06-24T15:31:48+00:00\",\"dateModified\":\"2022-04-13T16:33:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/\"},\"wordCount\":197,\"commentCount\":0,\"keywords\":[\"loop\",\"Php\",\"php framework\",\"phpsyntax\"],\"articleSection\":[\"php\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/\",\"name\":\"What is Loop What are the Syntax? - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-06-24T15:31:48+00:00\",\"dateModified\":\"2022-04-13T16:33:35+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/what-is-loop-what-are-the-syntax\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is Loop What are the Syntax?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/a40e0dd38feee7c2779460a804d49361\",\"name\":\"rajeshkumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g\",\"caption\":\"rajeshkumar\"},\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/rajeshkumar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Loop What are the Syntax? - scmGalaxy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/","og_locale":"en_US","og_type":"article","og_title":"What is Loop What are the Syntax? - scmGalaxy","og_description":"In this turorial i\u2019m going to learn about Lools, how to use and how to write. What is loop? A [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/","og_site_name":"scmGalaxy","article_published_time":"2021-06-24T15:31:48+00:00","article_modified_time":"2022-04-13T16:33:35+00:00","author":"rajeshkumar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rajeshkumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/"},"author":{"name":"rajeshkumar","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361"},"headline":"What is Loop What are the Syntax?","datePublished":"2021-06-24T15:31:48+00:00","dateModified":"2022-04-13T16:33:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/"},"wordCount":197,"commentCount":0,"keywords":["loop","Php","php framework","phpsyntax"],"articleSection":["php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/","name":"What is Loop What are the Syntax? - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-06-24T15:31:48+00:00","dateModified":"2022-04-13T16:33:35+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/what-is-loop-what-are-the-syntax\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"What is Loop What are the Syntax?"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/a40e0dd38feee7c2779460a804d49361","name":"rajeshkumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/82337e1fc8642c7f36795aa0775af055a4f38882994004b593efd31758d4434e?s=96&d=mm&r=g","caption":"rajeshkumar"},"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/rajeshkumar\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/6567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=6567"}],"version-history":[{"count":1,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/6567\/revisions"}],"predecessor-version":[{"id":6568,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/6567\/revisions\/6568"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=6567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=6567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=6567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}