如果还有问题 [英] If else problem

查看:61
本文介绍了如果还有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本if语句问题:


如果(....)

{

如果(.... )//如果1 ***

如果(....)//如果2 ***

如果(....)//如果3 * **

}

其他

if(....)

{

if(something = something)

{

if(....)// ***这和下一个2 If语句与那些语句相同/>
如果(....)//在上面的代码中......你如何避免重复相同的

如果(....)// if语句..这里只有3但是如果有10个怎么办?

}

}


避免重复相同if语句的一种解决方案是使用goto语句,但有没有其他更好的方法和优先的方式吗?


谢谢

解决方案


基本if语句问题:


如果(....)

{

如果(....)//如果1 ***

如果(....)//如果2 ***

如果(.. ..)//如果3 ***

}

其他

if(....)

{

if(something = something)

{

if(....)// ***这和下一个2如果语句与那些语句相同

if(....)//在上面的代码中......如果(....),你将如何避免重复相同的

)// if语句..这里只有3但是如果有10个怎么办?

}

}


一个解决方案为了避免重复相同的if语句是使用goto语句,但还有其他更好的方法吗?



谢谢



你可以使用一个函数:

展开 | 选择 | Wrap | 行号


您可以使该函数内联以避免调用开销。



你可以使用一个函数:

展开 | 选择 | Wrap | 行号


Basic if statement question:

If ( .... )
{
If (....) // If 1 ***
If (....) // If 2 ***
If (....) // If 3 ***
}
else
if ( .... )
{
if (something = something)
{
if (....) // *** This and the next 2 If statements are identical to those
if (....) // in code above... how would you avoid duplicating the same
if (....) // if statements.. here are only 3 but what if there are 10s?
}
}

One solution to avoid duplicating the the same if statements is to use goto statement, but is there any othe rbetter and preferred way of doing it?


Thanks

解决方案

Basic if statement question:

If ( .... )
{
If (....) // If 1 ***
If (....) // If 2 ***
If (....) // If 3 ***
}
else
if ( .... )
{
if (something = something)
{
if (....) // *** This and the next 2 If statements are identical to those
if (....) // in code above... how would you avoid duplicating the same
if (....) // if statements.. here are only 3 but what if there are 10s?
}
}

One solution to avoid duplicating the the same if statements is to use goto statement, but is there any othe rbetter and preferred way of doing it?


Thanks

you could use a function:

Expand|Select|Wrap|Line Numbers


And you could make that function inline to avoid the overhead of a call.


you could use a function:

Expand|Select|Wrap|Line Numbers


这篇关于如果还有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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