3 Replies - 189 Views - Last Post: 14 October 2012 - 01:13 PM Rate Topic: -----

#1 jmart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 29-September 12

Can you put more than one do-while?

Posted 14 October 2012 - 12:45 PM

I am trying to create a program, but I am wondering if I can have two do-whiles with if and else. It may be a very simple answer but I figured I'd ask.
I'm just making this example up but here it goes:
	do
	{
	System.out.println("This is example one");
	exampleOne = keyboard.nextDouble();
	}
	while (whatever<0 && whatever>100);
	if(whatever<0)
		System.out.println("Invalid number. Must be greater than zero");
	else(whatever>100);
		System.out.println("Valid number.");
        do
        {
        System.out.println("This is example two");
	exampleTwo = keyboard.nextDouble();
	}
	while (whatever<50 && whatever>150);
	if(whatever<50)
		System.out.println("Invalid number. Must be greater than 50");
	else(whatever>150);
		System.out.println("Valid number.");


This post has been edited by jmart: 14 October 2012 - 12:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Can you put more than one do-while?

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 3,133
  • Joined: 05-April 11

Re: Can you put more than one do-while?

Posted 14 October 2012 - 12:51 PM

Bad example ^^
This while will never be true
while (whatever<0 && whatever>100);



or this
while (whatever<50 && whatever>150);



I believe you wanted to write
while (whatever<50 || whatever>150);



There is no point of having the if else in your code since your while loops will make sure the input is valid

Post another example :D
Was This Post Helpful? 0
  • +
  • -

#3 jmart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 29-September 12

Re: Can you put more than one do-while?

Posted 14 October 2012 - 12:56 PM

I knew it would be a bad example haha I am still new to this :tup:
So you're saying I can have multiple while loops? Do you have an adequate example?
Was This Post Helpful? 0
  • +
  • -

#4 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 3,133
  • Joined: 05-April 11

Re: Can you put more than one do-while?

Posted 14 October 2012 - 01:13 PM

View Postjmart, on 14 October 2012 - 07:56 PM, said:

I knew it would be a bad example haha I am still new to this :tup:
So you're saying I can have multiple while loops? Do you have an adequate example?


Yes you can have multiple while loops in your code O.o
I am unsure if this is really your question :D

You can always try and make it in code and run it to see if it works
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1