以下是一个类似表达式的不同之处:
int a, b;
bool p = false;
while (cin >> a >> b and not p) { // code }
// and:
int a, b;
bool p = false;
while (not p and cin >> a >> b) { // code }
以下是一个类似表达式的不同之处:
int a, b;
bool p = false;
while (cin >> a >> b and not p) { // code }
// and:
int a, b;
bool p = false;
while (not p and cin >> a >> b) { // code }
while (i < vector.size() && condition(vector[i]))
false
,那么在条件中访问vector[i]
时程序将崩溃。然而,它并没有到达那个点。这只是短路运算符的众多用途之一。and
和 or
。我更喜欢 &&
和 ||
。我将它们写成大写字母只是为了指出它们是布尔运算符。 - therainmakerand
和 or
的存在只是因为这个问题!(也许我曾经知道,但从未使用过,所以...) - Stevewhile (cin >> a >> b and not p)
p
。如果输入失败,则结束循环并且不检查p
。另一方面:while (not p and cin >> a >> b)