{"id":73,"date":"2026-05-20T08:03:34","date_gmt":"2026-05-20T08:03:34","guid":{"rendered":"https:\/\/gigz.pk\/php\/?post_type=lesson&#038;p=73"},"modified":"2026-05-21T14:38:11","modified_gmt":"2026-05-21T14:38:11","slug":"for-loop","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/php\/?lesson=for-loop","title":{"rendered":"For Loop"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduction<br>A for loop is a control structure used in programming to repeat a block of code a specific number of times. It is commonly used when the number of repetitions is known in advance. In PHP and many other programming languages, the for loop helps developers write efficient and clean code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How For Loop Works<br>A for loop works by repeating a set of instructions until a condition becomes false. It consists of three main parts: initialization, condition, and increment or decrement. These parts work together to control how many times the loop will run.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Syntax of For Loop<br>for (initialization; condition; increment)<br>statement block<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example Explanation<br>First, the initialization sets the starting point. Second, the condition checks whether the loop should continue. Third, the increment updates the value after each iteration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP For Loop Example<br>PHP for loop example structure is<br>php<br>for ($i = 1; $i &lt;= 5; $i++)<br>echo $i<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This example will display numbers from 1 to 5 by repeating the code five times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Benefits of Using For Loop<br>It reduces repetitive code<br>It improves code readability<br>It saves development time<br>It is useful for working with arrays and data sets<br>It is essential for automation tasks in programming<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common Uses of For Loop<br>Displaying numbers in sequence<br>Processing arrays and lists<br>Generating repeated HTML elements<br>Running calculations multiple times<br>Handling database records in loops<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Practice Exercise<br>Try creating a for loop that prints numbers from 1 to 10. Then modify it to print only even numbers.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/php\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PHP Fundamentals (Beginner Level) > Loops > for Loop<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779264211713\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":16,"template":"","class_list":["post-73","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>For Loop - Learn PHP with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn PHP for loop basics with simple examples, syntax, and practice exercises for beginners in web development training online\" \/>\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\/php\/?lesson=for-loop\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"For Loop - Learn PHP with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn PHP for loop basics with simple examples, syntax, and practice exercises for beginners in web development training online\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/php\/?lesson=for-loop\" \/>\n<meta property=\"og:site_name\" content=\"Learn PHP with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-21T14:38:11+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\\\/php\\\/?lesson=for-loop\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=for-loop\",\"name\":\"For Loop - Learn PHP with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\"},\"datePublished\":\"2026-05-20T08:03:34+00:00\",\"dateModified\":\"2026-05-21T14:38:11+00:00\",\"description\":\"Learn PHP for loop basics with simple examples, syntax, and practice exercises for beginners in web development training online\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=for-loop#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=for-loop\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=for-loop#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/php\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Fundamentals (Beginner Level) > Loops > for Loop\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/\",\"name\":\"Learn PHP with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?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":"For Loop - Learn PHP with GiGz.PK","description":"Learn PHP for loop basics with simple examples, syntax, and practice exercises for beginners in web development training online","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\/php\/?lesson=for-loop","og_locale":"en_US","og_type":"article","og_title":"For Loop - Learn PHP with GiGz.PK","og_description":"Learn PHP for loop basics with simple examples, syntax, and practice exercises for beginners in web development training online","og_url":"https:\/\/gigz.pk\/php\/?lesson=for-loop","og_site_name":"Learn PHP with GiGz.PK","article_modified_time":"2026-05-21T14:38:11+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\/php\/?lesson=for-loop","url":"https:\/\/gigz.pk\/php\/?lesson=for-loop","name":"For Loop - Learn PHP with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/php\/#website"},"datePublished":"2026-05-20T08:03:34+00:00","dateModified":"2026-05-21T14:38:11+00:00","description":"Learn PHP for loop basics with simple examples, syntax, and practice exercises for beginners in web development training online","breadcrumb":{"@id":"https:\/\/gigz.pk\/php\/?lesson=for-loop#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/php\/?lesson=for-loop"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/php\/?lesson=for-loop#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/php"},{"@type":"ListItem","position":2,"name":"PHP Fundamentals (Beginner Level) > Loops > for Loop"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/php\/#website","url":"https:\/\/gigz.pk\/php\/","name":"Learn PHP with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/php\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}