{"id":5095,"date":"2014-03-30T18:45:41","date_gmt":"2014-03-30T18:45:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-use-variable-inside-for-l-loop-in-list-batch-file-programming-collection-of-common-programming-errors\/"},"modified":"2014-03-30T18:45:41","modified_gmt":"2014-03-30T18:45:41","slug":"how-to-use-variable-inside-for-l-loop-in-list-batch-file-programming-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-use-variable-inside-for-l-loop-in-list-batch-file-programming-collection-of-common-programming-errors\/","title":{"rendered":"How to use variable inside For \/L Loop IN List ( Batch File Programming)-Collection of common programming errors"},"content":{"rendered":"<p>Mark has identified a missing space between IN and (, but can&#8217;t tell if that is your actual code or just a typo when you created the question.<\/p>\n<p>Another possibility is that your variable is being set within the same code that later expands the value. The following code will fail:<\/p>\n<pre><code>(\n  set \/p \"myvariable=Enter a value: \"\n  echo myvariable=%myvariable%\n)\n<\/code><\/pre>\n<p>The reason the above fails is that the % expansion occurs when the statement is parsed, and the entire block within the parentheses is treated as a single statement. So it expands to the value that existed prior to executing the SET \/P.<\/p>\n<p>If you want the value that exists at run time, then you need to use delayed expansion<\/p>\n<pre><code>setlocal enableDelayedExpansion\n(\n  set \/p \"myvariable=Enter a value: \"\n  echo myvariable=!myvariable!\n)\n<\/code><\/pre>\n<p>This type of problem frequently occurs with IF and FOR commands. I can&#8217;t tell if this is your problem because you haven&#8217;t provided enough context.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mark has identified a missing space between IN and (, but can&#8217;t tell if that is your actual code or just a typo when you created the question. Another possibility is that your variable is being set within the same code that later expands the value. The following code will fail: ( set \/p &#8220;myvariable=Enter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5095","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5095"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5095\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}