标签: if-statement

如果带有String比较的语句失败

我真的不知道为什么下面的if语句没有执行:

if (s == "/quit")
{
    System.out.println("quitted");
}
Run Code Online (Sandbox Code Playgroud)

以下是全班.

这可能是一个非常愚蠢的逻辑问题,但我一直在把头发拉到这里,但是无法解决这个问题.

谢谢你看:)

class TextParser extends Thread {
    public void run() {
        while (true) {
            for(int i = 0; i < connectionList.size(); i++) {
                try {               
                    System.out.println("reading " + i);
                    Connection c = connectionList.elementAt(i); 
                    Thread.sleep(200);

                    System.out.println("reading " + i);

                    String s = "";

                    if (c.in.ready() == true) {
                        s = c.in.readLine();
                        //System.out.println(i + "> "+ s);

                        if (s == "/quit") {
                            System.out.println("quitted");
                        }

                        if(! s.equals("")) {
                            for(int j = 0; j < …
Run Code Online (Sandbox Code Playgroud)

java multithreading if-statement string-comparison

42
推荐指数
6
解决办法
37万
查看次数

XPath中是否有"if -then - else"语句?

似乎xpath中所有丰富的函数都可以执行"if".但是,我的引擎一直坚持"没有这样的功能",我几乎没有在网上找到任何文档(我发现了一些可疑的来源,但他们的语法不起作用)

我需要从字符串的末尾删除':'(如果存在),所以我想这样做:

if (fn:ends-with(//div [@id='head']/text(),': '))
            then (fn:substring-before(//div [@id='head']/text(),': ') )
            else (//div [@id='head']/text())
Run Code Online (Sandbox Code Playgroud)

有什么建议?

xpath if-statement

42
推荐指数
2
解决办法
10万
查看次数

是否需要执行if(log.isDebugEnabled()){...}检查?

有没有必要做一个明确的if(log.isDebugEnabled()){...}检查?

我的意思是我看到一些帖子提到log.debug("something")在进行日志记录之前进行隐式调用以查看是否已启用调试模式日志记录.我错过了什么,或者在使用之前是否有中间步骤?

谢谢!

log.debug("ResultSet rs is retrieved from OracleTypes");
Run Code Online (Sandbox Code Playgroud)

VS

if(log.isDebugEnabled()){
     log.debug("ResultSet rs is retrieved from OracleTypes");
}
Run Code Online (Sandbox Code Playgroud)

编辑:写了这篇文章:http: //java.sg/whether-to-do-a-isdebugenabled-checking-before-printing-out-your-log-statement/

java logging if-statement log4j

42
推荐指数
4
解决办法
3万
查看次数

在if语句中定义JavaScript变量

在if语句中定义JavaScript变量是否正确?

if(a==1){
    var b = 1;
} else {
    var b = 0;
}
Run Code Online (Sandbox Code Playgroud)

我知道上面的代码可行,但是,WebMatrix强调了变量.

我应该在if语句之外定义变量吗?或者第一个选项是正确的?或者它真的没关系?

var b = '';
if(a==1){
    b = 1;
} else {
    b = 0;
}
Run Code Online (Sandbox Code Playgroud)

javascript variables if-statement

42
推荐指数
1
解决办法
4万
查看次数

如果var == False

在python中,您可以编写if语句,如下所示

var = True
if var:
    print 'I\'m here'
Run Code Online (Sandbox Code Playgroud)

没有==,有没有办法做相反的事情,例如

var = False
if !var:
    print 'learnt stuff'
Run Code Online (Sandbox Code Playgroud)

python if-statement

42
推荐指数
3
解决办法
8万
查看次数

如何避免编写request.GET.get()两次才能打印出来?

我来自PHP背景,想知道是否有办法在Python中执行此操作.

在PHP中你可以像这样用一块石头杀死2只鸟:

代替:

if(getData()){
    $data = getData();
    echo $data;
}
Run Code Online (Sandbox Code Playgroud)

我可以做这个:

if($data = getData()){
    echo $data;
}
Run Code Online (Sandbox Code Playgroud)

您检查是否getData()存在,如果存在,则将其分配给一个语句中的变量.

我想知道在Python中是否有办法做到这一点?所以不要这样做:

if request.GET.get('q'):
    q = request.GET.get('q')
    print q
Run Code Online (Sandbox Code Playgroud)

避免写request.GET.get('q')两次.

python dictionary if-statement

41
推荐指数
3
解决办法
3万
查看次数

41
推荐指数
7
解决办法
7万
查看次数

Bash - 有什么用"fi ;;"?

我一直在寻找解释.以下是apt-fast.sh脚本的一个真实示例:

if [ ! -x /usr/bin/axel ]
then echo "axel is not installed, perform this?(y/n)"
    read ops
    case $ops in
     y) if apt-get install axel -y --force-yes
           then echo "axel installed"
        else echo "unable to install the axel. you are using sudo?" ; exit
        fi ;;
     n) echo "not possible usage apt-fast" ; exit ;;
    esac
fi
Run Code Online (Sandbox Code Playgroud)

"fi ;;"if街区中间有什么用?

bash if-statement

41
推荐指数
4
解决办法
7万
查看次数

如果条件在Makefile中,则在目标内

我正在尝试设置一个Makefile来搜索和复制一些文件(if-else条件),我无法弄清楚它到底出了什么问题?(你我很确定这是因为空格/标签的组合写在错误的地方).我可以得到一些帮助吗?

这是我目前的情况:

obj-m = linuxmon.o

KDIR = /lib/modules/$(shell uname -r)/build
UNAME := $(shell uname -m)

all:

    $(info Checking if custom header is needed)
    ifeq ($(UNAME), x86_64)
        $(info Yes)
        F1_EXISTS=$(shell [ -e /usr/include/asm/unistd_32.h ] && echo 1 || echo 0 )
        ifeq ($(F1_EXISTS), 1)
            $(info Copying custom header)
            $(shell sed -e 's/__NR_/__NR32_/g' /usr/include/asm/unistd_32.h > unistd_32.h)
        else    
            F2_EXISTS=$(shell [[ -e /usr/include/asm-i386/unistd.h ]] && echo 1 || echo 0 )
            ifeq ($(F2_EXISTS), 1)
                $(info Copying custom header)
                $(shell sed -e 's/__NR_/__NR32_/g' /usr/include/asm-i386/unistd.h > …
Run Code Online (Sandbox Code Playgroud)

if-statement makefile target

41
推荐指数
2
解决办法
14万
查看次数

if子句中的多个条件

如果我有一个需要满足这些要求的if语句:

if(cave > 0 && training > 0 && mobility > 0 && sleep > 0)
Run Code Online (Sandbox Code Playgroud)

有没有办法说它们都大于零?只是为了更有效的DRY代码?

就像是:

if(cave, training, mobility, sleep > 0)
Run Code Online (Sandbox Code Playgroud)

javascript if-statement

41
推荐指数
4
解决办法
4990
查看次数