首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从经典ASP中的函数提前返回

从经典ASP中的函数提前返回
EN

Stack Overflow用户
提问于 2010-02-04 23:58:01
回答 2查看 26.4K关注 0票数 23

在传统的ASP中,有没有办法提前从一个函数返回,而不是运行整个函数?例如,假设我有一个函数...

代码语言:javascript
复制
Function MyFunc(str)
  if (str = "ReturnNow!") then
    Response.Write("What up!")       
  else
    Response.Write("Made it to the end")     
  end if
End Function

我可以这样写吗?

代码语言:javascript
复制
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中这样做。有没有办法在返回语句所在位置中断代码执行?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-02-04 23:59:43

是的,使用exit function

代码语言:javascript
复制
Function MyFunc(str)
  if str = "ReturnNow!" then
    Response.Write("What up!")       
    Exit Function
  end if

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

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

代码语言:javascript
复制
Function usefulFunc(str)
   ''# Validate Input
   If str = "" Then
      usefulFunc = ""
      Exit Function
   End If 

   ''# Real function 
   ''# ...
End Function
票数 39
EN

Stack Overflow用户

发布于 2010-02-05 00:02:02

在传统的ASP中,你需要使用Exit Function

代码语言:javascript
复制
Function MyFunc(str)
  if (str = "ReturnNow!") then
    Response.Write("What up!")       
    Exit Function
  end if

  Response.Write("Made it to the end")     
End Function
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2201072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档