Switch statement inside loop

Hey guys,

I am working on a project where I want to take an array of strings and use a switch statement to execute certain actions depending on each of the values. I’ve done something similar in C++ for other projects outside of UiPath, but it’s giving me a hard time here and I’m not sure at this point what I am doing wrong.

I have tried using “for each” and “while” (with counter) loops.

Each time, the problem is that the switch statement executes only once, for the first item in my array. I am pretty sure the problem is not with my loop since I can print the values of each array element using either the for each or while loop.

Any suggestions for how to fix this so that the switch statement executes for each iteration of my loop?

Screenshot below of the code that is giving me issues. This one uses the for each loop, but like I’ve said, I also have tried while loops with counters.

1 Like

Ok small update, and I’m feeling silly about this one, but in case it helps anyone else, turned out the solution to my problem was that I had leading/trailing whitespaces in some of my array elements causing the switch cases to not match the data.

Adding .trim to my switch expression fixed it as you can see below.

image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.