Batch Script – Return Code - Classic for Loop Implementation - Batch Script

Following is the classic ‘for’ statement which is available in most programming languages.


The Batch Script language does not have a direct ‘for’ statement which is similar to the above syntax, but one can still do an implementation of the classic ‘for’ loop statement using if statements and labels.

Following is the general flow of the classic ‘for’ loop statement.


Let’s look at the general syntax implementation of the classic for loop in batch scripting.

  • The entire code for the ‘for’ implementation is placed inside of a label.
  • The counters variables must be set or initialized before the ‘for’ loop implementation starts.
  • The expression for the ‘for’ loop is done using the ‘if’ statement. If the expression evaluates to be true then an exit is executed to come out of the loop.
  • A counter needs to be properly incremented inside of the ‘if’ statement so that the ‘for’ implementation can continue if the expression evaluation is false.
  • Finally, we will go back to our label so that we can evaluate our ‘if’ statement again.

Following is an example of how to carry out the implementation of the classic ‘for’ loop statement.



The above command produces the following output.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Batch Script Topics