我的If条件是我的代码 [英] My If Condition is Skipping my code

查看:54
本文介绍了我的If条件是我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if(Dir.contains("a"))
{
//Dir=folder
}
if(Dir.contains("b"))
{
// code
}



如果条件失败,我的第一个例外是我的第一个,如果条件也跳过第二个,我想允许它如果第一次失败则转到第二条件。


My exception is my first if condition is failed so its skipping 2nd if condition too, I want to allow it to go to 2nd if condition if 1st fails.

推荐答案

你应该使用If和elseif:

You should use If and elseif instead:
if (x) {

} else if (y) {

}


使用 ladder-If

use ladder-If
if(Dir.contains("a"))
{
//Dir=folder
}
else if(Dir.contains("b") //this code-block will be executed if first condition fails
{
// code
}
else// ********* Optional 
{
 //execute if all of above conditions failed 
}



你可以使用切换案例



Happy Coding!

:)


you can use Switch case also

Happy Coding!
:)


这篇关于我的If条件是我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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