{"id":14519,"date":"2025-04-16T21:51:05","date_gmt":"2025-04-16T14:51:05","guid":{"rendered":"https:\/\/www.krujeen.com\/?p=14519"},"modified":"2025-04-16T21:57:15","modified_gmt":"2025-04-16T14:57:15","slug":"%e0%b8%84%e0%b8%b3%e0%b8%aa%e0%b8%b1%e0%b9%88%e0%b8%87-loop-for-%e0%b9%83%e0%b8%99-c","status":"publish","type":"post","link":"https:\/\/www.krujeen.com\/?p=14519","title":{"rendered":"\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07 loop for \u0e43\u0e19 C++"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/www.krujeen.com\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-16-2025-09_55_17-PM-1024x683.png\" alt=\"\" class=\"wp-image-14522\" srcset=\"https:\/\/www.krujeen.com\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-16-2025-09_55_17-PM-1024x683.png 1024w, https:\/\/www.krujeen.com\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-16-2025-09_55_17-PM-300x200.png 300w, https:\/\/www.krujeen.com\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-16-2025-09_55_17-PM-768x512.png 768w, https:\/\/www.krujeen.com\/wp-content\/uploads\/2025\/04\/ChatGPT-Image-Apr-16-2025-09_55_17-PM.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. for loop \u0e1e\u0e37\u0e49\u0e19\u0e10\u0e32\u0e19<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">for (\u0e01\u0e32\u0e23\u0e40\u0e23\u0e34\u0e48\u0e21\u0e15\u0e49\u0e19; \u0e40\u0e07\u0e37\u0e48\u0e2d\u0e19\u0e44\u0e02; \u0e01\u0e32\u0e23\u0e40\u0e1b\u0e25\u0e35\u0e48\u0e22\u0e19\u0e41\u0e1b\u0e25\u0e07) {\n    \/\/ \u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07\u0e17\u0e35\u0e48\u0e08\u0e30\u0e17\u0e33\u0e0b\u0e49\u0e33\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">for (int i = 0; i &lt; 5; i++) {\n    std::cout &lt;&lt; i &lt;&lt; \" \";\n}\n\/\/ \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c: 0 1 2 3 4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. for loop \u0e41\u0e1a\u0e1a\u0e19\u0e31\u0e1a\u0e16\u0e2d\u0e22\u0e2b\u0e25\u0e31\u0e07<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">\nfor (int i = 10; i &gt; 0; i--) {\n    cout &lt;&lt; i &lt;&lt; \" \";\n}\n\/\/ \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c: 10 9 8 7 6 5 4 3 2 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. for loop \u0e01\u0e31\u0e1a\u0e01\u0e32\u0e23\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e02\u0e31\u0e49\u0e19\u0e15\u0e2d\u0e19\u0e40\u0e2d\u0e07<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">for (int i = 0; i &lt;= 10; i += 2) {\n    cout &lt;&lt; i &lt;&lt; \" \";\n}\n\/\/ \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c: 0 2 4 6 8 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. for loop \u0e17\u0e35\u0e48\u0e21\u0e35\u0e2b\u0e25\u0e32\u0e22\u0e15\u0e31\u0e27\u0e41\u0e1b\u0e23<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">for (int i = 0, j = 10; i &lt; 5; i++, j--) {\n    cout &lt;&lt; i &lt;&lt; \":\" &lt;&lt; j &lt;&lt; \" \";\n}\n\/\/ \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c: 0:10 1:9 2:8 3:7 4:6<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. for loop \u0e0b\u0e49\u0e2d\u0e19 for loop (Nested for loop)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">for (int i = 0; i &lt; 3; i++) {\n    for (int j = 0; j &lt; 3; j++) {\n        cout &lt;&lt; \"(\" &lt;&lt; i &lt;&lt; \",\" &lt;&lt; j &lt;&lt; \") \";\n    }\n    cout &lt;&lt; endl;\n}\n\/\/ \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c:\n\/\/ (0,0) (0,1) (0,2)\n\/\/ (1,0) (1,1) (1,2)\n\/\/ (2,0) (2,1) (2,2)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6. Range-based for loop (C++11 \u0e02\u0e36\u0e49\u0e19\u0e44\u0e1b)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">vector&lt;int&gt; numbers = {1, 2, 3, 4, 5};\nfor (int num : numbers) {\n    cout &lt;&lt; num &lt;&lt; \" \";\n}\n\/\/ \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c: 1 2 3 4 5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>7. for loop \u0e01\u0e31\u0e1a iterator<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">vector&lt;int&gt; vec = {10, 20, 30, 40, 50};\nfor (auto it = vec.begin(); it != vec.end(); ++it) {\n    cout &lt;&lt; *it &lt;&lt; \" \";\n}\n\/\/ \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c: 10 20 30 40 50<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>8. for loop \u0e44\u0e21\u0e48\u0e21\u0e35\u0e40\u0e07\u0e37\u0e48\u0e2d\u0e19\u0e44\u0e02 (Infinite loop)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">for (;;) {\n    \/\/ \u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07\u0e17\u0e35\u0e48\u0e08\u0e30\u0e17\u0e33\u0e0b\u0e49\u0e33\u0e44\u0e1b\u0e40\u0e23\u0e37\u0e48\u0e2d\u0e22\u0e46\n    \/\/ \u0e15\u0e49\u0e2d\u0e07\u0e21\u0e35\u0e40\u0e07\u0e37\u0e48\u0e2d\u0e19\u0e44\u0e02\u0e01\u0e32\u0e23\u0e2b\u0e22\u0e38\u0e14 (break) \u0e20\u0e32\u0e22\u0e43\u0e19\u0e25\u0e39\u0e1b\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>9. for loop \u0e01\u0e31\u0e1a comma operator<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">for (int i = 0, j = 0; i + j &lt; 10; i++, j += 2) {\n    cout &lt;&lt; i &lt;&lt; \"+\" &lt;&lt; j &lt;&lt; \"=\" &lt;&lt; (i + j) &lt;&lt; \" \";\n}\n\/\/ \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c: 0+0=0 1+2=3 2+4=6 3+6=9<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u0e2b\u0e21\u0e32\u0e22\u0e40\u0e2b\u0e15\u0e38:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e43\u0e0a\u0e49 <code>break<\/code> \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e2d\u0e2d\u0e01\u0e08\u0e32\u0e01 loop \u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e1a\u0e23\u0e2d\u0e1a<\/li>\n\n\n\n<li>\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e43\u0e0a\u0e49 <code>continue<\/code> \u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e02\u0e49\u0e32\u0e21\u0e01\u0e32\u0e23\u0e17\u0e33\u0e07\u0e32\u0e19\u0e43\u0e19\u0e23\u0e2d\u0e1a\u0e1b\u0e31\u0e08\u0e08\u0e38\u0e1a\u0e31\u0e19\u0e41\u0e25\u0e30\u0e44\u0e1b\u0e22\u0e31\u0e07\u0e23\u0e2d\u0e1a\u0e16\u0e31\u0e14\u0e44\u0e1b<\/li>\n\n\n\n<li>\u0e23\u0e30\u0e27\u0e31\u0e07\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49 for loop \u0e41\u0e1a\u0e1a\u0e44\u0e21\u0e48\u0e21\u0e35\u0e17\u0e35\u0e48\u0e2a\u0e34\u0e49\u0e19\u0e2a\u0e38\u0e14 (infinite loop) \u0e42\u0e14\u0e22\u0e44\u0e21\u0e48\u0e15\u0e31\u0e49\u0e07\u0e43\u0e08<\/li>\n\n\n\n<li>Range-based for loop \u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\u0e07\u0e48\u0e32\u0e22\u0e41\u0e25\u0e30\u0e2d\u0e48\u0e32\u0e19\u0e07\u0e48\u0e32\u0e22 \u0e41\u0e15\u0e48\u0e43\u0e0a\u0e49\u0e44\u0e14\u0e49\u0e01\u0e31\u0e1a C++11 \u0e02\u0e36\u0e49\u0e19\u0e44\u0e1b\u0e40\u0e17\u0e48\u0e32\u0e19\u0e31\u0e49\u0e19<\/li>\n\n\n\n<li>\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49 auto \u0e43\u0e19 for loop \u0e01\u0e31\u0e1a iterator \u0e0a\u0e48\u0e27\u0e22\u0e43\u0e2b\u0e49\u0e42\u0e04\u0e49\u0e14\u0e22\u0e37\u0e14\u0e2b\u0e22\u0e38\u0e48\u0e19\u0e21\u0e32\u0e01\u0e02\u0e36\u0e49\u0e19<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1. for loop \u0e1e\u0e37\u0e49\u0e19\u0e10\u0e32\u0e19 \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07: 2. for loop \u0e41\u0e1a\u0e1a\u0e19\u0e31\u0e1a\u0e16\u0e2d\u0e22\u0e2b\u0e25\u0e31\u0e07 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14522,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[155,156],"tags":[160],"class_list":["post-14519","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programing","category-c_language","tag-c"],"_links":{"self":[{"href":"https:\/\/www.krujeen.com\/index.php?rest_route=\/wp\/v2\/posts\/14519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.krujeen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.krujeen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.krujeen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.krujeen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14519"}],"version-history":[{"count":3,"href":"https:\/\/www.krujeen.com\/index.php?rest_route=\/wp\/v2\/posts\/14519\/revisions"}],"predecessor-version":[{"id":14523,"href":"https:\/\/www.krujeen.com\/index.php?rest_route=\/wp\/v2\/posts\/14519\/revisions\/14523"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.krujeen.com\/index.php?rest_route=\/wp\/v2\/media\/14522"}],"wp:attachment":[{"href":"https:\/\/www.krujeen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.krujeen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.krujeen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}