gpt4 book ai didi

java - java或Processing中是否有 "unless"函数?除非满足某个参数,否则运行代码的东西?

转载 作者:行者123 更新时间:2023-12-02 12:50:54 25 4
gpt4 key购买 nike

这可能是一个愚蠢的问题,但有没有什么可以做到这一点:

unless (boolean==true){
do aThing;
} otherwise {
do somethingElse;
}

编辑:我的意思不是“if/else”语句。我对这些非常熟悉。

以下是我所讨论内容的更准确示例:

Scanner in = new Scanner(System.in);

int amountOfThings= in.nextInt();

for (int i = 0; i <=amountOfThings;i++){

unless (amountOfThings==20){
System.out.println(i);
}
}

最佳答案

几个选项:

if(thing){
//do the thing
}
else{
//do the other thing
}

这会检查 thing 是否为真,如果是,则执行第一个 block 。如果不是,则执行 else block 。

或者您可以使用 ! not 运算符:

if(!thing){
//do the other thing
}

这使用了 ! not 运算符,它反转了 thing。换句话说,这会检查 thing 是否为 false,如果是,则执行代码块。

编辑:您的示例如下:

if (amountOfThings != 20){
System.out.println(i);
}

无耻的 self 推销:here是有关处理中 if 语句的教程。

关于java - java或Processing中是否有 "unless"函数?除非满足某个参数,否则运行代码的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44617413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com