多个返回语句与转到 [英] Multiple return statements Vs goto's

查看:78
本文介绍了多个返回语句与转到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些函数中,我需要在
多个地方返回多个错误代码,我使用多个return语句。比如说。

if(Found == 1)

{

if(val == -1)

返回error1;

}

else

{

if(val2 == -1)

返回error2;

}

返回成功;

这只是一个简单的例子。我的案例有很多有条件的

语句。


另一种方法是使用goto语句。让我知道

更好的方法,这是更好的选择(多次返回

语句或Goto')


谢谢,

In some functions where i need to return multiple error codes at
multiple places, I use multiple return statements. Say for ex.
if (Found == 1)
{
if (val == -1)
return error1;
}
else
{
if (val2 == -1)
return error2;
}
return success;
This is just a simple example. My case have lot of conditional
statements.

the alternate approach is to use goto statements. Let me know the
better way of doing this and which is preferrable (multiple return
statements or Goto''s)

Thanks,

推荐答案

su *********** @ gmail.com 写道:
在某些函数中我需要返回多个错误代码
地方,我使用多个return语句。比如说。
if(Found == 1)
{
if if(val == -1)
return error1;
}
else
{
如果(val2 == -1)
返回error2;
}
返回成功;
这只是一个简单的例子。我的案例有很多条件语句。

替代方法是使用goto语句。让我知道更好的方法,这是更好的方式(多个返回
语句或Goto')

谢谢,
In some functions where i need to return multiple error codes at
multiple places, I use multiple return statements. Say for ex.
if (Found == 1)
{
if (val == -1)
return error1;
}
else
{
if (val2 == -1)
return error2;
}
return success;
This is just a simple example. My case have lot of conditional
statements.

the alternate approach is to use goto statements. Let me know the
better way of doing this and which is preferrable (multiple return
statements or Goto''s)

Thanks,




使用gotos,你可以让所有出口点跳到函数末尾附近的公共点

,这对于放置常见的清理代码或者/>
调试语句。如果你有多个返回值,你需要多个

goto标签。



With gotos, you can make all the exit points jump to a common point near
the end of the function, which is useful to place common clean-up code or
debug statements. If you have multiple return values, you''ll need multiple
goto labels.


#替代方法是使用goto语句。让我知道

#更好的方法,这是更好的选择(多次返回

#语句或Goto')


多个返回语句是go-tos。


-

SM Ryan http://www.rawbw.com/~wyrmwif/

如果你的工作和他们的工作一样毫无意义,那么你也疯了吗?
# the alternate approach is to use goto statements. Let me know the
# better way of doing this and which is preferrable (multiple return
# statements or Goto''s)

Multiple return statements are go-tos.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
If your job was as meaningless as theirs, wouldn''t you go crazy too?




sureshjaya ... @ gmail.com写道:

sureshjaya...@gmail.com wrote:
In我需要在多个地方返回多个错误代码的一些函数,我使用多个return语句。比如说。
if(Found == 1)
{
if if(val == -1)
return error1;
}
else
{
如果(val2 == -1)
返回error2;
}
返回成功;
这只是一个简单的例子。我的案例有很多条件语句。

替代方法是使用goto语句。让我知道更好的方法,这是更好的方式(多个返回
语句或Goto')

谢谢,
In some functions where i need to return multiple error codes at
multiple places, I use multiple return statements. Say for ex.
if (Found == 1)
{
if (val == -1)
return error1;
}
else
{
if (val2 == -1)
return error2;
}
return success;
This is just a simple example. My case have lot of conditional
statements.

the alternate approach is to use goto statements. Let me know the
better way of doing this and which is preferrable (multiple return
statements or Goto''s)

Thanks,







首选多个''return''语句而不是''goto''。


-vs_p ......



Hi,

Prefer multiple ''return'' statements than ''goto''.

-vs_p...


这篇关于多个返回语句与转到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆