Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning early from a function in classic ASP

Tags:

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?

like image 970
Rob Segal Avatar asked Feb 04 '10 15:02

Rob Segal


1 Answers

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 
like image 74
C. Ross Avatar answered Dec 02 '22 00:12

C. Ross