标签: conditional

Javascript'if'有条件不...条件

我正在检查我博客上的一些"阅读更多"链接,并隐藏链接(前两个帖子),或者隐藏内容并保留链接.我id通过一个如下所示的if ... else语句运行链接的属性:

$(document).find('.contentclicker').each(function(){
    var pt = $(this).parent().attr('id');
    if (pt == "postnum1" ||  "postnum2"){
        $(this).hide();
    }
    else{
        $(this).next().hide();
    }

    });
Run Code Online (Sandbox Code Playgroud)

注意:那里有一些jQuery,但它并不相关.我从调试中知道var pt正确设置为post_num_1,post_num_2等等 - 但是当它评估post_num_3等等时,它不会转到else.我试过=====,除其他事项外,我想不出有什么不对.

有什么建议?

javascript conditional

0
推荐指数
1
解决办法
618
查看次数

在条件中声明两个变量?

我可以在C++中的条件语句中声明两个变量.编译器给出了错误,但我认为我应该得到一个意见:

int main()
{
    double d1 = 0;
    if((double d2 = d1) || (double d3 = 10))
        cout << "wow" << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ conditional declaration

0
推荐指数
1
解决办法
1286
查看次数

Python如果条件有两个条件依赖于元组

我最近才开始用Python编程(以前的Ruby经验).我试图设置一个有两个条件的if条件:

if not previous[1] and previous[0][0] == 5:
            print "hello world"
Run Code Online (Sandbox Code Playgroud)

但是,我不断收到此错误:

<type 'exceptions.IndexError'>: tuple index out of range 
Run Code Online (Sandbox Code Playgroud)

打印上一个回报: ((5, 1, 9, 23),)

我究竟做错了什么?

我正在寻找类似于Ruby语法的东西: unless previous[1]

ruby python conditional tuples python-2.7

0
推荐指数
1
解决办法
260
查看次数

检查数字是否在一定范围内的Python方法

以下代码根据a变量所属的范围为v变量分配一个特定的值。

if v>0 and v<1000:
    c='green'
elif v>=1000 and v<2000:
    c='yellow'
else:
    c='red'
Run Code Online (Sandbox Code Playgroud)

效果很好,但是我想知道是否还有更多的Python方式可以编写以下条件块。

python conditional

0
推荐指数
1
解决办法
901
查看次数

如何在R中按组省略两个最高值和最低值的行

这似乎是一个非常基本的问题,但我似乎无法找到解决方案.

你怎么去掉两个最高及的(三级)行的最低值variable由R中的几个因素是什么?我已经修改airquality了一点来得到一个例子(抱歉,我还是初学者):

set.seed(1)
airquality$var1 <- c(sample(1:3, 153, replace=T))
airquality$var2 <- c(sample(1:2, 153, replace=T))
airquality2 <- airquality
airquality2$Solar.R <- as.numeric(airquality2$Solar.R)
airquality2$Solar.R <- airquality2$Solar.R*2
airquality3 <- airquality
airquality3$Solar.R <- as.numeric(airquality3$Solar.R)
airquality3$Solar.R <- airquality3$Solar.R*2.5
test <- round(na.omit(rbind(airquality, airquality2, airquality3)))
test$var1 <- factor(test$var1)
test$var2 <- factor(test$var2)
head(test)
Run Code Online (Sandbox Code Playgroud)

来到:

head(test)

#   Ozone Solar.R Wind Temp Month Day var1 var2
# 1    41     190    7   67     5   1    1    1
# 2    36     118    8   72     5   2    2    2 …
Run Code Online (Sandbox Code Playgroud)

conditional r max

0
推荐指数
1
解决办法
194
查看次数

奇怪的Bash if/elif行为

我有以下脚本:

a=$1
b=$2

if [ ! a ]; then
    echo "a=$a"
elif [ b ]; then
    echo "b=$b"
fi
Run Code Online (Sandbox Code Playgroud)

这是我可以称之为的四种可能方式:

balter$ bash eliftest.sh true true
b=true
balter$ bash eliftest.sh true false
b=false
balter$ bash eliftest.sh false true
b=true
balter$ bash eliftest.sh false false
b=false
Run Code Online (Sandbox Code Playgroud)

我原以为:

b=true # !a evaluates to false but b is true
<nothing> # !a evaluates to false and b is also false
a=false # !a evaluates to true and if short circuits 
a=false # !a evaluates …
Run Code Online (Sandbox Code Playgroud)

bash shell conditional if-statement

0
推荐指数
1
解决办法
185
查看次数

else语句遵循哪个顺序?

我想确定一些事情,

当我有多个if/else条件并且if并不意味着其中一个else条件的if条件; 下一个else陈述是否适用于最后一个if陈述?

例如:

if(condition1)
{
    //operation1
}

if(condition2)
{
    //operation2
}

else
{
    //operation3.  
}
Run Code Online (Sandbox Code Playgroud)

像上面的例子一样,如果我不使用a else作为第一个if语句,哪个if语句else可以用于?如果我没有指定else每个问题,这会对我造成问题if吗?

我做了一些测试,但想确定这实际上是如何工作的.

c conditional if-statement

0
推荐指数
1
解决办法
168
查看次数

如果回到父母那里

我有这种代码

if(a == 3) {
  if(b == 4) {
    // do somthing
  } else {
    // do an other thing  
  }
} else {
  // do the same other thing  
}
Run Code Online (Sandbox Code Playgroud)

我想知道,当我在第一个时else,我怎么能去第二个,else因为它将执行相同的代码

谢谢

java conditional if-statement

0
推荐指数
1
解决办法
41
查看次数

Swift 3 - 将Int32转换为Int

使用Swift 3并且在IF语句中比较Int32和Int时遇到问题.

// myIntFromCoreData is an Int32
// kMyConstant is an Int

if myIntFromCoreData == kMyConstant // error: Binary operator "==" cannot be applied to operands of type 'Int32' and 'Int'
{
     Log("Cool")
}
Run Code Online (Sandbox Code Playgroud)

所以,我尝试使用以下方法将值转换为Int32或Int:

myint32.intValue // Value of type 'Int32' has no member 'intValue'

myint32 as Int // Cannot convert value of type 'Int32' to type 'Int' in coercion

kMyConstant as Int32 // Cannot convert value of type 'Int' to type 'Int32' in coercion
Run Code Online (Sandbox Code Playgroud)

但不断得到上述错误.任何人都可以提供一些方向,如何处理这个?

int conditional casting int32 swift3

0
推荐指数
1
解决办法
6702
查看次数

我如何有条件地检查枚举是否是一种变体?

我有一个包含两个变体的枚举:

enum DatabaseType {
    Memory,
    RocksDB,
}
Run Code Online (Sandbox Code Playgroud)

如果在检查参数是否为DatabaseType::Memory或的函数内部进行条件化,我需要什么DatabaseType::RocksDB

fn initialize(datastore: DatabaseType) -> Result<V, E> {
    if /* Memory */ {
        //..........
    } else if /* RocksDB */ {
        //..........
    }
}
Run Code Online (Sandbox Code Playgroud)

enums conditional rust

0
推荐指数
1
解决办法
2188
查看次数

标签 统计

conditional ×10

if-statement ×3

python ×2

bash ×1

c ×1

c++ ×1

casting ×1

declaration ×1

enums ×1

int ×1

int32 ×1

java ×1

javascript ×1

max ×1

python-2.7 ×1

r ×1

ruby ×1

rust ×1

shell ×1

swift3 ×1

tuples ×1