Need Help with a do while loop I'm not sure if right Please Help!!
Hey guys i need help i am trying to execute a do while loop and don't know how to do it properly and to stop the loop please help me
Code Java:
class Category{
public static void main(String[] args){
// Declare Variables
int age, x = 1;
int s=0;
// User Input
do
{
System.out.print("Enter your age : "); // Read Data
age = Keyboard.readInt();
System.out.print(x);
// Decisions
if (age < 14){
System.out.print("You are in Category A ");}
else if(age < 16){
System.out.print("You are in Category B ");}
else if(age >= 16){
System.out.print("You are in Category C ");}
else
System.out.print(s);
} while (x <=10);
}
}
Re: Need Help with a do while loop I'm not sure if right Please Help!!
Re: Need Help with a do while loop I'm not sure if right Please Help!!
Thanks for replying but i don't know how to stop a do while loop or have an if statement so i can stop it please help me
Re: Need Help with a do while loop I'm not sure if right Please Help!!
You could make a bool variable and set it as second condition to the do-while loop.
When you change the bool you stop the loop.
Re: Need Help with a do while loop I'm not sure if right Please Help!!
i understand but could u give me an example please
Re: Need Help with a do while loop I'm not sure if right Please Help!!
Sure.
Code :
boolean run=true;
do{}
while(condition&&run);
Re: Need Help with a do while loop I'm not sure if right Please Help!!
i got it thanks for the help man