警告:条件中的字符串文字 [英] warning: string literal in condition
本文介绍了警告:条件中的字符串文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用下面的第一段代码,我收到两条警告消息:警告:条件中的字符串文字
x2
Using the first bit of code below I receive two warning messages:
warning: string literal in condition
x2
if input == "N" || "n"
#do this
else input == "L" || "l"
#do this
与使用它相反,它不会导致任何警告
as opposed to using this which results in no warnings
if input == "N" || input == "n"
#do this
else input == "L" || input == "l"
#do this
我想知道为什么第一部分代码会导致警告,以及使用它的缺点.
I'm wondering why the first bit of code results in a warning, and the downside of using it.
推荐答案
change input == "N" ||"n"
到
input == "N" || input == "n"
您还必须使用 else if
而不是 else
You must also use else if
instead of else
警告是说你有一个字符串文字n",而不是一个布尔值或测试,它总是评估为真.
这篇关于警告:条件中的字符串文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文