gpt4 book ai didi

asp-classic - 从经典 ASP 中的函数提前返回

转载 作者:行者123 更新时间:2023-12-03 11:35:26 25 4
gpt4 key购买 nike

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

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

可以这样写吗...
Function MyFunc(str)
if (str = "ReturnNow!") then
Response.Write("What up!")
return
end if

Response.Write("Made it to the end")
End Function

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

最佳答案

是使用 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

我通常在从函数返回值时使用它。
Function usefulFunc(str)
''# Validate Input
If str = "" Then
usefulFunc = ""
Exit Function
End If

''# Real function
''# ...
End Function

关于asp-classic - 从经典 ASP 中的函数提前返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2201072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com