Hello,

I have a function that has some Case statements that contain a For loop. The general purpose of the code is to match a parameter to the appropriate case then iterate through the For loop until a value is matched from a list of roles. When that value is matched, I would like the function to terminate immediately and return the matched value.

This is some pseudocode for the function. My problem is that even though I have the return statement (function name is set to a value) the for loop is processed to the end rather than terminating immediately. In my mind, this wastes time and is inefficient. Should I use an Exit Function statement? I most commonly see that associated with returning errors.

Thanks in advance for the help!


Function Test (param1 as String) As Currency

Case param1 = 1

for i = 0 to i =35

if( list(i) = param1) then
Test = i 'I would like the function to terminate immediately here rather than contine to process
end if


End Function