在IF语句被触发为True之后,从此代码内部移动到IF语句的Else部分

问题描述 投票:0回答:1

我很想知道一件事。是否有可能在.NET(或您可能遇到的任何语言)中执行此方案:

下面的伪代码:

if(statement)
  //do something
  //Because you calculated or read something else, **drop|go|navigate** to else part
  //(not necessarily error or exception)
  //rest of if-true code continues, but is not executed because you moved to else
else
 //do something in else part, code continues here and is executed till the end normally
end-if

在你投票给我之前,我知道这是一个完美的try-throw-catch可解决的实现,这就是我现在解决的问题。

在if中我不需要抛出异常,因为在逻辑和BI方面绝对没有异常。

我需要知道它是否支持.NET或任何其他语言通过if声明而不抛出异常或使用try-catch实现它。

尽可能简单,我的问题是:即使if(true)被触发,是否可以执行if条件的Else部分?我可以在if(true)中改变主意吗?

if-statement coding-style implementation
1个回答
0
投票

在某些编程语言中,您可以使用LABELS和GOTO

但了解这个问题有助于找到一个好的解决方案。似乎IF / ELSE不是你想要的,为什么不使用2 ifs?如果你想直接进入第二个选项...也许在函数/方法内关闭,并在需要时调用。更好地解释问题,也许我们可以更好地解决问题:P

© www.soinside.com 2019 - 2024. All rights reserved.