【发布时间】:2019-07-08 11:49:42
【问题描述】:
好的,基本上这就是脚本的样子:
echo -n "Guess my number: "
read guess
while [ $guess != 5 ]; do
echo Your answer is $guess. This is incorrect. Please try again.
echo -n "What is your guess? "
read guess
done
echo "That's correct! The answer was $guess!"
我要改变的是这一行:
while [ $guess != 5 ]; do
这样的:
while [ $guess != 5 and $guess != 10 ]; do
在 Java 中,我知道“and”是“&&”,但这在这里似乎不起作用。我是否使用 while 循环以正确的方式解决这个问题?
【问题讨论】:
-
问题标题原本是“or”而不是“and”。当然,根据德摩根定律,无论您将要求表述为“我想要 5 或 10”还是双重否定“我不想要一个不是 5 和不是 10 的答案”,这在逻辑上都是一样的.