What is the best datatype for iterating through months of the year within UiPath using a for each activity?
Question: A user needs to download a report for each month of the year and decides to loop over the months using a “For Each” activity. Which datatype(s) are best-suited to hold the values of the names of the months?
- List(Of String)
- String – Array for String
Option B and D are correct.
A For Each loop activity can iterate through lists, arrays, DataTables or any type of collection. It would be a good idea to hold the names of each month in a collection such as an array or list. As B and D are collections, these are the correct answers.
While you could argue that a string is a collection of characters and you should be able to loop through them, it’s not the best fit for this problem. We are looking for the best datatype for this problem and the name of months don’t natually fit as characters in a string. Also, when it comes to strings, while and do while loop lend themselves better as the use of indicies is natural.
As a generic type cannot be a collection, we cannot use this to store months.