Is there a way to return early from a function in classic ASP rather than it run the full length of the function? For example lets say I have the function...
Function MyFunc(str) if (str = "ReturnNow!") then Response.Write("What up!") else Response.Write("Made it to the end") end if End Function
Can I write it like so...
Function MyFunc(str) if (str = "ReturnNow!") then Response.Write("What up!") return end if Response.Write("Made it to the end") End Function
Note the return statement which of course I can't do in classic ASP. Is there a way to break code execution where that return statement sits?
Yes using exit function
.
Function MyFunc(str) if str = "ReturnNow!" then Response.Write("What up!") Exit Function end if Response.Write("Made it to the end") End Function
I commonly use this when returning a value from a function.
Function usefulFunc(str) ''# Validate Input If str = "" Then usefulFunc = "" Exit Function End If ''# Real function ''# ... End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With