Loops
There have been statements enacted sequentially in the decision-making chapter. Alternatively, Batch Script can also be used to alter the flow of control in a program’s logic. These statements are then organized into flow control statements.
Serial No | Loops | Description |
---|---|---|
1 | While Statement Implementation | There is no direct while statement in Batch Script, although labels and an if statement can be used to implement this loop. |
2 | For Statement – List Implementations | Batch files can loop using the “FOR” construct. In order to work with a list of values, the ‘for’ statement requires the following construct. |
3 | Looping through Ranges | ‘For’ statements can also move through ranges of values. A general version is presented below. |
4 | Classic for Loop Implementation | It has the classic ‘for’ statement found in many programming languages. |
5 | Break Statement Implementation | Within any programming language, the break statement is used to alter the flow of control inside a loop. As part of looping constructs, the break statement causes the innermost enclosing loop to terminate immediately |
Batch Script – Return code
Return codes are the codes returned by programs when they are executed. If the command line is successful, it should return zero; if it is not successful, it should return non-zero. If the test fails, a non-zero value indicates the error number, and the user can attempt to resolve it by navigating to the error message.
The test may also return an exit code. A program’s or utility’s exit code usually appears when it finishes or terminates.
The list below includes some of the non-zero exit codes (with their respective errors) that programs may return
Error Code | Description |
---|---|
0 | Successful completion of the program. |
1 | This error indicates that the Windows command prompt has attempted to execute an unrecognized action |
2 | An error indicating that the file could not be found in the specified location |
3 | An error message indicated that the specified path could not be found. |
5 | An indication that the user is not authorized to access the resource |
90090×2331 | This error occurs when you misspell the command, application name, or path when configuring an Action. |
2212254950xC0000017-1073741801 | The error message tells you that Windows has run out of memory. |
32212257860xC000013A-1073741510 | This indicates that the user terminated the application |
32212257940xC0000142-1073741502 | The message indicating that the application was launched on a desktop to which the current user doesn’t have access |