在C ++中使用多个条件的While循环 [英] While loop with multiple conditions in C++
本文介绍了在C ++中使用多个条件的While循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何制作一个循环,直到满足多个条件之一为止.例如:
做{srand(time(0));estrength = rand()%100);srand(time(0));强度= rand()%100);} while()//力量或力量都不等于100
有一个la脚的例子,但我想大家都会明白的.
我知道&& ;,但我希望它只满足其中一个条件并继续前进,不能同时满足这两个条件.
解决方案
使用 ||
和/或&&
运算符组合您的条件./p>
示例:
1.
做{...} while(a || b);
将在 a
或 b
为真时循环.
2.
做{...} while(a&& b);
当 a
和 b
为真时,
将循环.
How would I make a loop that does the loop until one of multiple conditions is met. For example:
do
{
srand (time(0));
estrength = rand()%100);
srand (time(0));
strength = rand()%100);
} while( ) //either strength or estrength is not equal to 100
Kind of a lame example, but I think you all will understand.
I know of &&, but I want it to only meet one of the conditions and move on, not both.
解决方案
Use the ||
and/or the &&
operators to combine your conditions.
Examples:
1.
do
{
...
} while (a || b);
will loop while either a
or b
are true.
2.
do
{
...
} while (a && b);
will loop while both a
and b
are true.
这篇关于在C ++中使用多个条件的While循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文