Loops/Foreach: Difference between revisions

Content added Content deleted
Line 274: Line 274:


=={{header|Batch File}}==
=={{header|Batch File}}==
The FOR command can imitate the "Foreach Loop". The whitespace and the comma (,) are the default delimiters.<br><br>
The FOR command can imitate the "Foreach Loop". The whitespace and the comma (,) are the default delimiters.<br>
'''Direct usage:'''
'''Direct usage:'''
<lang dos>@echo off
<lang dos>@echo off
for %%A in (This is a sample sentence) do (
for %%A in (This is a sample collection) do (
echo %%A
echo %%A
)</lang>
)</lang>
'''Using a Collection Variable:'''
'''Using a Collection Variable:'''
<lang dos>@echo off
<lang dos>@echo off
set "collection=This is a sample sentence"
set "collection=This is a sample collection"
for %%A in (%collection%) do (
for %%A in (%collection%) do (
echo %%A
echo %%A