{"id":30289,"date":"2023-01-14T10:59:02","date_gmt":"2023-01-14T05:29:02","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/"},"modified":"2023-01-14T10:59:02","modified_gmt":"2023-01-14T05:29:02","slug":"solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/","title":{"rendered":"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-31759476\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"31759476\" data-parentid=\"31759349\" data-score=\"3\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p><strong>The syntax of a for loop in <code>C programming language<\/code> is:<\/strong><\/p>\n<pre><code>for ( init; condition; increment )\n{\n   statement(s);\n}\n<\/code><\/pre>\n<ul>\n<li>\n<p>Here is the flow of control in a for loop:<\/p>\n<ol>\n<li>\n<p>The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.<\/p>\n<\/li>\n<li>\n<p>Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement just after the for loop.<\/p>\n<\/li>\n<li>\n<p>After the body of the for loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition.<\/p>\n<\/li>\n<li>\n<p>The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the for loop terminates.<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h2>In First Case:<\/h2>\n<ul>\n<li><code>init<\/code>  set <code>i = 1<\/code> <\/li>\n<li><code>conditon<\/code> &#8211; here <code>i = 1<\/code> which is <code>true<\/code> in c.  (Post increment increases the value after execution of statment)<\/li>\n<li><code>body<\/code>  &#8211; executes <code>printf(\"%d\",i);<\/code> <\/li>\n<li><code>increment<\/code>  &#8211; <code>i&lt;100<\/code> which is not affecting the value of <code>i<\/code>. <\/li>\n<\/ul>\n<p>Now In C for all values from 1 to infinity, its value is true, hence executing infinetly<\/p>\n<h2>In Second Case<\/h2>\n<ul>\n<li><code>init<\/code>  set <code>i = 0<\/code> <\/li>\n<li><code>conditon<\/code> &#8211; here <code>i = 0<\/code> (again Post Increment) which is <code>false<\/code> in c, therefore the <code>loop<\/code> gets exit. <\/li>\n<\/ul>\n<p>Hence it is not executing even once. <\/p>\n<h2>Flow diagram of For Loop :<\/h2>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png\"><img decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png\" alt=\"enter image description here\"><\/a><\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved what happens when increment counter and test counter are interchanged in for-loop syntax? [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] The syntax of a for loop in C programming language is: for ( init; condition; increment ) { statement(s); } Here is the flow of control in a for loop: The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not &#8230; <a title=\"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/\" aria-label=\"More on [Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,593],"class_list":["post-30289","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-for-loop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed] - JassWeb<\/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:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] The syntax of a for loop in C programming language is: for ( init; condition; increment ) { statement(s); } Here is the flow of control in a for loop: The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-14T05:29:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\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:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed]\",\"datePublished\":\"2023-01-14T05:29:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/\"},\"wordCount\":283,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png\",\"keywords\":[\"c++\",\"for-loop\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/\",\"name\":\"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png\",\"datePublished\":\"2023-01-14T05:29:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#primaryimage\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed] - JassWeb","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:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed] - JassWeb","og_description":"[ad_1] The syntax of a for loop in C programming language is: for ( init; condition; increment ) { statement(s); } Here is the flow of control in a for loop: The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/","og_site_name":"JassWeb","article_published_time":"2023-01-14T05:29:02+00:00","og_image":[{"url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png","type":"","width":"","height":""}],"author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed]","datePublished":"2023-01-14T05:29:02+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/"},"wordCount":283,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png","keywords":["c++","for-loop"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/","name":"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#primaryimage"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png","datePublished":"2023-01-14T05:29:02+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#primaryimage","url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2023\/01\/Solved-what-happens-when-increment-counter-and-test-counter-are.png"},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-what-happens-when-increment-counter-and-test-counter-are-interchanged-in-for-loop-syntax-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] what happens when increment counter and test counter are interchanged in for-loop syntax? [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/30289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=30289"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/30289\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=30289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=30289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=30289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}