{"id":4258,"date":"2018-08-17T08:00:07","date_gmt":"2018-08-17T07:00:07","guid":{"rendered":"https:\/\/code-maze.com\/?p=4258"},"modified":"2021-12-20T14:16:43","modified_gmt":"2021-12-20T13:16:43","slug":"csharp-loops","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-loops\/","title":{"rendered":"While, For, Do-While Loops in C#"},"content":{"rendered":"<p>In this article, we are going to learn how to use loops in C#, what type of loops exist, and when to use them. We will use a couple of examples to closely explain the usage of each loop in C#.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">If you want to download the source code for our examples, you can do that from here <a href=\"https:\/\/github.com\/CodeMazeBlog\/csharp-back-to-basics\/tree\/loops\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Loops in C# Source Code<\/a>.<\/div>\n<p>For the complete navigation of this series check out: <a href=\"https:\/\/code-maze.com\/csharp-back-to-basics\/\" target=\"_blank\" rel=\"noopener noreferrer\">C# Back to Basics.<\/a><\/p>\n<p>In this article, we are going to talk about:<\/p>\n<ul>\n<li><a href=\"#whileloop\">While Loop<\/a><\/li>\n<li><a href=\"#forloop\">For Loop<\/a><\/li>\n<li><a href=\"#dowhileloop\">Do-While Loop<\/a><\/li>\n<\/ul>\n<p>Let&#8217;s dig in.<\/p>\n<h2 id=\"whileloop\">While Loop<\/h2>\n<p>While loop is a loop with a precondition. This means that we are checking a condition first and then if a condition returns true, we execute our expression:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">while(condition)\r\n{\r\n   &lt; expression &gt; ;\r\n}\r\n<\/pre>\n<p><em>Example 1: Create an application that calculates the sum of all the numbers from n to m (inputs from a user):<\/em><\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        Console.WriteLine(\"Enter the integer n number:\");\r\n        int n = Convert.ToInt32(Console.ReadLine());\r\n\r\n        Console.WriteLine(\"Enter the integer m number\");\r\n        int m = Convert.ToInt32(Console.ReadLine());\r\n\r\n        int sum = 0;\r\n\r\n        while(n &lt;= m)\r\n        {\r\n            sum += n;\r\n            n++;\r\n        }\r\n\r\n        Console.WriteLine($\"Sum from n to m is {sum}\");\r\n        Console.ReadKey();\r\n    }\r\n}\r\n<\/pre>\n<p>The result:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Enter the integer n number:\r\n5\r\nEnter the integer m number\r\n25\r\nSum from n to m is 315<\/pre>\n<p>So let&#8217;s explain the code above.<\/p>\n<p>Because we calculate the sum of all numbers from &#8220;n&#8221; to &#8220;m&#8221;, we need to have a variable to store that value. It needs to be initialized with a zero at the beginning. Without that, our app will fail to build due to the sum variable being unassigned.<\/p>\n<p>In a while loop, we are going through all the numbers from <code>n<\/code> to <code>m<\/code> and adding every number to the sum variable. We are using this expression: <code>sum += n;<\/code> which is a shorter for <code>sum = sum + n;<\/code><\/p>\n<p>Finally, we need to increment the <code>n<\/code> variable by 1. Without that, we would have an infinite loop because the value of the <code>n<\/code> variable would always be lesser than the value of the <code>m<\/code> variable.<\/p>\n<p>We should use while loops when the number of iterations is uncertain. This means that we could repeat iteration until some condition is fulfilled, but we are not sure how many iterations we would need to reach the condition fulfillment.<\/p>\n<h2 id=\"forloop\">For Loop<\/h2>\n<p>For loop is another loop with a precondition. We use the following syntax to write it in C#:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">for (initialization; condition; progression;)\r\n{\r\n    &lt;loop body &gt; ;\r\n}\r\n<\/pre>\n<p>We use initialization at the beginning of the loop and it serves the purpose of initializing the variable with a value. The condition is used to determine when the loop is completed. Progression is a part in which we increment or decrement our variable initialized in the initialization part. The body consists of all the expressions we need to execute as long as the condition is true.<\/p>\n<p>It is important to know that the order of execution is: Initialization, Condition, Loop Body, Progression.<\/p>\n<p><em>Example 1: Create an application that calculates the sum of all the numbers from n to m (inputs from a user):<\/em><\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        Console.WriteLine(\"Enter the integer n number:\");\r\n        int n = Convert.ToInt32(Console.ReadLine());\r\n\r\n        Console.WriteLine(\"Enter the integer m number\");\r\n        int m = Convert.ToInt32(Console.ReadLine());\r\n\r\n        int sum = 0;\r\n\r\n        for(int i = n; i &lt;= m; i++)\r\n        {\r\n            sum += i;\r\n        }\r\n\r\n        Console.WriteLine($\"Sum from n to m is {sum}\");\r\n\r\n        Console.ReadKey();\r\n\r\n    }\r\n}\r\n<\/pre>\n<p>The result:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Enter the integer n number:\r\n98\r\nEnter the integer m number:\r\n327\r\nSum from n to m is 48875<\/pre>\n<p><em>Example 2:\u00a0 Create an application that prints out all the integer numbers from n to 1:<\/em><\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        Console.WriteLine(\"Enter number n that is greater than 1: \");\r\n        int n = Convert.ToInt32(Console.ReadLine());\r\n\r\n        for (int i = n; i &gt;= 1; i--)\r\n        {\r\n            Console.WriteLine(i);\r\n        }\r\n\r\n        Console.ReadKey();\r\n    }\r\n}\r\n<\/pre>\n<p>Result:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Enter number n that is greater than 1:\r\n10\r\n10\r\n9\r\n8\r\n7\r\n6\r\n5\r\n4\r\n3\r\n2\r\n1<\/pre>\n<p>We should use for loops when we know how many iterations we are going to have. This means if we iterate through all the elements inside a collection or we have an ending point for iterations.<\/p>\n<h2 id=\"dowhileloop\">Do-While Loop<\/h2>\n<p>The do-while loop is a loop with postcondition. What this means is that the loop body is executed first and the condition is checked after. That&#8217;s totally opposite from the previous loop examples.<\/p>\n<p>Let&#8217;s inspect the implementation of this loop:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">do\r\n{\r\n    &lt; expression &gt; ;\r\n} while (condition);\r\n<\/pre>\n<p>Now, let&#8217;s practice a bit.<\/p>\n<p><em>Example 1: Create an application that calculates the sum of all the numbers from n to m (inputs from a user):<\/em><\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        Console.WriteLine(\"Enter the integer n number:\");\r\n        int n = Convert.ToInt32(Console.ReadLine());\r\n\r\n        Console.WriteLine(\"Enter the integer m number\");\r\n        int m = Convert.ToInt32(Console.ReadLine());\r\n\r\n        int sum = 0;\r\n\r\n        do\r\n        {\r\n            sum += n;\r\n            n++;\r\n        } while (n &lt;= m);\r\n\r\n        Console.WriteLine($\"The sum from n to m is {sum}\");\r\n        Console.ReadKey();\r\n    }\r\n}\r\n<\/pre>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/24-Do_while_Example1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4256\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/24-Do_while_Example1.png\" alt=\"Do-while example 1 Loops in C#\" width=\"267\" height=\"95\" \/><\/a><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Enter the integer n number:\r\n24\r\nEnter the integer m number:\r\n38\r\nThe sum from n to m is 465<\/pre>\n<p><em>Example 2: Create an application that prints out the sum of all the even numbers to n:<\/em><\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        Console.WriteLine(\"Enter the upper border number n: \");\r\n        int n = Convert.ToInt32(Console.ReadLine());\r\n\r\n        int sum = 2;\r\n        int startingNumber = 4;\r\n\r\n        do\r\n        {\r\n            sum += startingNumber;\r\n            startingNumber += 2;\r\n        }while (startingNumber &lt;= n);\r\n\r\n        Console.WriteLine($\"Sum of all the even numbers to n is {sum}\");\r\n        Console.ReadKey();\r\n    }\r\n}\r\n<\/pre>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/25-Do_while_Example2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4257\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/25-Do_while_Example2.png\" alt=\"Do-while example 2\" width=\"333\" height=\"98\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/25-Do_while_Example2.png 333w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/25-Do_while_Example2-300x88.png 300w\" sizes=\"auto, (max-width: 333px) 100vw, 333px\" \/><\/a><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Enter the upper border number n:\r\n10\r\nSum of all the even numbers to n is 30<\/pre>\n<h2>Conclusion<\/h2>\n<p>Now we can implement iterations in a combination with all that we have learned from the previous articles, thus making our application more powerful.<\/p>\n<p>In our next post, we are going to talk about how to <a href=\"https:\/\/code-maze.com\/csharp-basics-handling-exceptions\/\" target=\"_blank\" rel=\"noopener noreferrer\">handle exceptions in C#<\/a>.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to learn how to use loops in C#, what type of loops exist, and when to use them. We will use a couple of examples to closely explain the usage of each loop in C#. For the complete navigation of this series check out: C# Back to Basics. In [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":54459,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[505,12],"tags":[264,262,261,263],"class_list":["post-4258","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-basic","category-csharp","tag-do-while","tag-for","tag-loops","tag-while","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# Basics - Loops in C# (For, While and Do-While Loops)<\/title>\n<meta name=\"description\" content=\"Learn more about Loops in C#. How to use them and when to use them and what are the differences. Learn all of that through the examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-loops\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Basics - Loops in C# (For, While and Do-While Loops)\" \/>\n<meta property=\"og:description\" content=\"Learn more about Loops in C#. How to use them and when to use them and what are the differences. Learn all of that through the examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-loops\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-17T07:00:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-20T13:16:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinko Spasojevi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinko Spasojevi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/\"},\"author\":{\"name\":\"Marinko Spasojevi\u0107\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\"},\"headline\":\"While, For, Do-While Loops in C#\",\"datePublished\":\"2018-08-17T07:00:07+00:00\",\"dateModified\":\"2021-12-20T13:16:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/\"},\"wordCount\":618,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png\",\"keywords\":[\"Do-While\",\"For\",\"Loops\",\"While\"],\"articleSection\":[\"Basic\",\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-loops\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/\",\"url\":\"https:\/\/code-maze.com\/csharp-loops\/\",\"name\":\"C# Basics - Loops in C# (For, While and Do-While Loops)\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png\",\"datePublished\":\"2018-08-17T07:00:07+00:00\",\"dateModified\":\"2021-12-20T13:16:43+00:00\",\"description\":\"Learn more about Loops in C#. How to use them and when to use them and what are the differences. Learn all of that through the examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-loops\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png\",\"width\":1100,\"height\":620,\"caption\":\"09 loops\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-loops\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"While, For, Do-While Loops in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\",\"name\":\"Marinko Spasojevi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"caption\":\"Marinko Spasojevi\u0107\"},\"description\":\"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/marinko\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# Basics - Loops in C# (For, While and Do-While Loops)","description":"Learn more about Loops in C#. How to use them and when to use them and what are the differences. Learn all of that through the examples.","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:\/\/code-maze.com\/csharp-loops\/","og_locale":"en_US","og_type":"article","og_title":"C# Basics - Loops in C# (For, While and Do-While Loops)","og_description":"Learn more about Loops in C#. How to use them and when to use them and what are the differences. Learn all of that through the examples.","og_url":"https:\/\/code-maze.com\/csharp-loops\/","og_site_name":"Code Maze","article_published_time":"2018-08-17T07:00:07+00:00","article_modified_time":"2021-12-20T13:16:43+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png","type":"image\/png"}],"author":"Marinko Spasojevi\u0107","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Marinko Spasojevi\u0107","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-loops\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-loops\/"},"author":{"name":"Marinko Spasojevi\u0107","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533"},"headline":"While, For, Do-While Loops in C#","datePublished":"2018-08-17T07:00:07+00:00","dateModified":"2021-12-20T13:16:43+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-loops\/"},"wordCount":618,"commentCount":1,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-loops\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png","keywords":["Do-While","For","Loops","While"],"articleSection":["Basic","C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-loops\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-loops\/","url":"https:\/\/code-maze.com\/csharp-loops\/","name":"C# Basics - Loops in C# (For, While and Do-While Loops)","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-loops\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-loops\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png","datePublished":"2018-08-17T07:00:07+00:00","dateModified":"2021-12-20T13:16:43+00:00","description":"Learn more about Loops in C#. How to use them and when to use them and what are the differences. Learn all of that through the examples.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-loops\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-loops\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-loops\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/09-loops.png","width":1100,"height":620,"caption":"09 loops"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-loops\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"While, For, Do-While Loops in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533","name":"Marinko Spasojevi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","caption":"Marinko Spasojevi\u0107"},"description":"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.","sameAs":["https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/marinko\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=4258"}],"version-history":[{"count":2,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4258\/revisions"}],"predecessor-version":[{"id":61640,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4258\/revisions\/61640"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/54459"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=4258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=4258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=4258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}