从经典ASP中的函数早期返回

Rob*_*gal 22 asp-classic

有没有办法从经典ASP中的函数提前返回,而不是运行函数的全长?例如,假设我有这个功能......

Function MyFunc(str)
  if (str = "ReturnNow!") then
    Response.Write("What up!")       
  else
    Response.Write("Made it to the end")     
  end if
End Function
Run Code Online (Sandbox Code Playgroud)

我能这样写吗......

Function MyFunc(str)
  if (str = "ReturnNow!") then
    Response.Write("What up!")       
    return
  end if

  Response.Write("Made it to the end")     
End Function
Run Code Online (Sandbox Code Playgroud)

请注意返回语句,当然我在经典ASP中无法做到.有没有办法在返回语句所在的位置中断代码执行?

C. *_*oss 36

是的使用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
Run Code Online (Sandbox Code Playgroud)

我通常在从函数返回值时使用它.

Function usefulFunc(str)
   ''# Validate Input
   If str = "" Then
      usefulFunc = ""
      Exit Function
   End If 

   ''# Real function 
   ''# ...
End Function
Run Code Online (Sandbox Code Playgroud)