-3
do{
Scanner scan = new Scanner(System.in);
String value = scan.nextLine();
}while(!value.equals("example")/* need another condition here*/);

I want to put two(or more) conditions here, any one of them should be true to stop looping. Thanks for your help.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
Shahbaz Talpur
  • 315
  • 4
  • 17

4 Answers4

3

Boolean operators

AND (&&)

p   q   p && q
T   T   T
T   F   F
F   T   F
F   F   F

OR (||)

p   q   p || q
T   T   T
T   F   T
F   T   T
F   F   F

So, to use it in your conditions.

if (x != 9 && x != 10) { ... }

if (x == 0 || x == 5) { ... }
melpomene
  • 84,125
  • 8
  • 85
  • 148
Uma Kanth
  • 5,659
  • 2
  • 20
  • 41
2

Have you tried using && or || between conditions? I'm new and I hope I'm not telling the obvious.

... while(!value.equals("example") && otherCondition || !found)...

iSab
  • 41
  • 3
0

The condtion s: cond1, cond2, cond3, .... condN.

"any one of them should be true" = (cond1==true && cond2==true && cond3==true && ... condN==true)

I your code it will be like: stop looping = ! before all the expresstion

do{

}while(!(cond1==true && cond2==true && cond3==true && ... condN==true));

0

So if you want to stop the loop wenn either one of the statements is true or both of them are true, you need to use the boolean or operator "||".

If both of the statements should be true to stop the loop, you need to use boolena and operator "&&"

insa_c
  • 2,851
  • 1
  • 16
  • 11