Length of an Array
There is no predefined function to find the length of the array. We can use for loop and Iterate through the Array.
@echo off :: Here an array is defined set array[0]=1 set array[1]=4 set array[2]=9 set array[3]=10 :: Here we initializing an variable named :: len to calculate length of array set len=0 :: To iterate the element of array :Loop :: It will check if the element is defined or not if defined array[%len%] ( set /a len+=1 GOTO :Loop ) echo The length of the array is %len% pause
The above program produces the below output.
The length of the array is 4
Batch Script – Arrays
An array is a collection of elements of the same data type. The arrays are not explicitly defined as Batch Script types but can be used. The following items need to be noted when the same members are used in Batch Script.
- Each aspect of the same members needs to be defined by a set order.
- A ‘for’ loop will be required to double the program values.
Contact Us