标签: conditional-statements

Python,条件 - 这些是等价的吗?

if config == 'H/2' or 'H' or '2H': pass
if config == 'H/2' or config == 'H' or config == '2H': pass
Run Code Online (Sandbox Code Playgroud)

python conditional-statements

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

if/else条件在同一行上不起作用

为什么这不起作用?

if (condition) stuff; return;
else otherStuff;
Run Code Online (Sandbox Code Playgroud)

或这个

if (condition) stuff; return;
else {otherStuff;}
Run Code Online (Sandbox Code Playgroud)

我可以轻松解决这个问题:

if (condition) {stuff; return;}
else otherStuff;
Run Code Online (Sandbox Code Playgroud)

但我认为if语句阻止整行不排除返回.

java if-statement return conditional-statements

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

多个IF else条件和逻辑OR运算之间的差异

逻辑上是否有任何区别

if (name.startsWith("a"){
   return true;
} else if (name.startsWith("b") {
   return true;
} else if (name.startsWith("c") {
   return true;
}
Run Code Online (Sandbox Code Playgroud)

if(name.startsWith("a") || name.startsWith("b") || name.startsWith("c") ){
  return true;
}
Run Code Online (Sandbox Code Playgroud)

我更喜欢第二个,因为它对我来说很优雅.我想明白"有什么不同吗?"

java conditional-statements

1
推荐指数
2
解决办法
1226
查看次数

ISO中的(x <= y <= z)条件语法?

我已经看到条件语法如下所示,在示例代码中显示了很多,以检查整数值y是否在两个边界之间,x并且z:

if (x <= y <= z) { //... }
Run Code Online (Sandbox Code Playgroud)

我以为我在自己之前使用过这个,但是在一小段代码中我正在进行测试,条件总是评估为真......现在怀疑我自己的记忆因为我已经确定我以前用过它了!ISO C中允许的语法是什么?我只是期望它能做一些不应该做的事情吗?

老式的:

if (x >= y && x <= z) { //... } 
Run Code Online (Sandbox Code Playgroud)

仍然有魅力,所以我还没有完全回到召回的蹒跚阶段;)

c conditional-statements

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

为什么单个值可以作为一个条件

显然,在条件语句中,您需要确保返回true或false值,以执行或跳过与if语句关联的代码块.单个值如何在python中作为真正的布尔值?我不确定这是否适用于所有语言,但我在python 3.x中发现它.

例:

value = 1
if value:
   print("value == True") # prints every time
Run Code Online (Sandbox Code Playgroud)

我希望编译器抱怨或只返回false.为什么编译器会认为if value是真的?

python conditional-statements

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

如何使用窗口小部件选项值作为条件来创建if语句?

假设我有一个这个按钮:

tl.config(bd=0 ,image=photo1 ,width="100",height="100",command=lambda: functionPlus(tl))  
Run Code Online (Sandbox Code Playgroud)

功能是:

def functionPlus(button):

   global turn

   if (turn==1 or turn==3 or turn==5 or turn==7 or turn==9):
       button.config(image=photo2,width="100",height="100")
       turn +=1

   elif (turn==2 or turn==4 or turn==6 or turn==8) :
       button.config(image=photo3,width="100",height="100")
       turn+=1
Run Code Online (Sandbox Code Playgroud)

我想在函数中添加一个'if',它具有按钮图像的条件.举个例子 :

if button.config(image=photo2 == True) :
   anotherFunction()
Run Code Online (Sandbox Code Playgroud)

提前致谢.

python if-statement tkinter conditional-statements

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

TYPO3:TypoScript中的后端布局条件

我想根据页面的后端布局更改元素的呈现方式.
根据后端布局更改流体样式内容模板的工作方式如下:

[globalVar = TSFE:page|backend_layout = 1][globalVar = TSFE:page|backend_layout = 2]
lib.fluidContent.templateRootPaths.10 = EXT:ds_res/Resources/Private/Templates/ContentTemplates/
[global]
Run Code Online (Sandbox Code Playgroud)

如果是1或2,则使用其他模板.

但是,这仅在BE布局直接设置在页面上而不是从其父级继承时才有效.
如何解决这个问题?

运行TYPO3 7.6.15
谢谢.

typo3 conditional-statements typoscript

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

while循环输出多个条件

main()
{
    int i=0,j=0;
    while(i<5,j<10)
    {
        i++;
        j++;
    }
    printf("%d,%d,",i,j);
}
Run Code Online (Sandbox Code Playgroud)

输出: 10,10

int main(){
    int x=2,y=2;
    while(x<=5,y<=3)
         printf("%d %d ",++x, ++y);
    return 0;        
}
Run Code Online (Sandbox Code Playgroud)

输出: 3 3 4 4

在第一个代码中,输出如何产生10,10?任何人都可以解释,但第二个代码的输出是3344,是否都运行在不同的逻辑上?

c loops while-loop conditional-statements

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

仅当条件为true时,才从函数返回单行语句吗?

在C#中,是否有任何语法糖可以在单个语句中执行以下操作(基本上是有条件的返回):

public SomeBaseType MyFunction()
{
    // Can the two statements below be combined into one?
    SomeBaseType something = SomeFunction();
    if ( something != null ) { return something; }
    // End of statements regarding this question.


    // Do lots of other statements...
    return somethingElseThatIsADerivedTypeThatDoesntMatter;
}
Run Code Online (Sandbox Code Playgroud)

c# if-statement conditional-statements

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

Javascript三元布尔简写

以下JavaScript布尔三元表达式是否有速记语法:

var foo = (expression) ? true : false
Run Code Online (Sandbox Code Playgroud)

javascript ternary-operator conditional-statements

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