{"id":34,"date":"2026-05-20T17:31:28","date_gmt":"2026-05-20T17:31:28","guid":{"rendered":"https:\/\/gigz.pk\/csharp\/?post_type=lesson&#038;p=34"},"modified":"2026-05-20T17:37:12","modified_gmt":"2026-05-20T17:37:12","slug":"do-while-loop","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop","title":{"rendered":"do while Loop"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The do while loop in C# is used to repeat a block of code at least once and then continue repeating it as long as a specified condition remains true. It is useful when the code must run before checking the condition.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is do while Loop<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A do while loop is a control structure that executes the loop body first and then checks the condition. If the condition is true, the loop repeats; otherwise, it stops.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Structure of do while Loop<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The do while loop consists of a do block that contains the code to execute and a while condition that is checked after each iteration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do while Loop Works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The program first executes the code inside the do block. After execution, it checks the condition. If the condition is true, the loop runs again. This continues until the condition becomes false.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Condition in do while Loop<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The condition is evaluated after each iteration. This ensures that the loop runs at least one time, even if the condition is false initially.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Importance of do while Loop<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The do while loop is important when at least one execution is required before checking conditions. It is useful for menus, input validation, and repeated user prompts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Real World Usage<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">do while loops are used in menu-driven programs, user input validation systems, retry attempts, and interactive applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Difference from while Loop<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The main difference is that while loop checks the condition first, while do while loop checks the condition after executing the code block.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common Mistakes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Forgetting to update loop variables<br>Incorrect condition placement<br>Creating infinite loops<br>Syntax errors<br>Not understanding first execution rule<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Best Practices<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Ensure loop condition becomes false eventually<br>Always update variables inside the loop<br>Keep code inside loop simple<br>Use meaningful variable names<br>Test loop behavior carefully<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Lesson Summary<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The do while loop in C# ensures that a block of code runs at least once before checking the condition. It is useful for interactive programs and situations where initial execution is required.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/csharp\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">C# Fundamentals (Beginner Level) > Loops > do while Loop<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779298260996\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":18,"template":"","class_list":["post-34","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>do while Loop - Learn C# Language with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn C# do while loop with syntax and examples. Understand repetition and conditions with simple beginner-friendly guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"do while Loop - Learn C# Language with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn C# do while loop with syntax and examples. Understand repetition and conditions with simple beginner-friendly guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop\" \/>\n<meta property=\"og:site_name\" content=\"Learn C# Language with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-20T17:37:12+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=do-while-loop\",\"url\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=do-while-loop\",\"name\":\"do while Loop - Learn C# Language with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/#website\"},\"datePublished\":\"2026-05-20T17:31:28+00:00\",\"dateModified\":\"2026-05-20T17:37:12+00:00\",\"description\":\"Learn C# do while loop with syntax and examples. Understand repetition and conditions with simple beginner-friendly guide.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=do-while-loop#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=do-while-loop\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?lesson=do-while-loop#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/csharp\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# Fundamentals (Beginner Level) > Loops > do while Loop\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/\",\"name\":\"Learn C# Language with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/csharp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"do while Loop - Learn C# Language with GiGz.PK","description":"Learn C# do while loop with syntax and examples. Understand repetition and conditions with simple beginner-friendly guide.","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:\/\/gigz.pk\/csharp\/?lesson=do-while-loop","og_locale":"en_US","og_type":"article","og_title":"do while Loop - Learn C# Language with GiGz.PK","og_description":"Learn C# do while loop with syntax and examples. Understand repetition and conditions with simple beginner-friendly guide.","og_url":"https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop","og_site_name":"Learn C# Language with GiGz.PK","article_modified_time":"2026-05-20T17:37:12+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop","url":"https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop","name":"do while Loop - Learn C# Language with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/csharp\/#website"},"datePublished":"2026-05-20T17:31:28+00:00","dateModified":"2026-05-20T17:37:12+00:00","description":"Learn C# do while loop with syntax and examples. Understand repetition and conditions with simple beginner-friendly guide.","breadcrumb":{"@id":"https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/csharp\/?lesson=do-while-loop#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/csharp"},{"@type":"ListItem","position":2,"name":"C# Fundamentals (Beginner Level) > Loops > do while Loop"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/csharp\/#website","url":"https:\/\/gigz.pk\/csharp\/","name":"Learn C# Language with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/csharp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/csharp\/index.php?rest_route=\/wp\/v2\/lesson\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/csharp\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/csharp\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/csharp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}