How to create a loop thats includes a if statement

If I understand your question correctly, every time the loop runs, you want to decrease “powerlevel” by a random value, then display a message depending on whether powerlevel can be reduced. Here are two approaches. 1) use an if statement in your for loop for (conditions){ if(powerlevel cannot be decremented){ //display a messsage break; } … Read more

C++: While Looping Amount of Times

this is a suitable time to utilize the do while loop the way it works is it will execute the statement within the block without evaluating any conditions and then evaluate the condition to determine if the loop should run again this is what your program could look like #include <iostream> using namespace std; int … Read more

I don't know what's wrong with the do-while loop

Try below code : public static void main(String[] args) { String responded; do{ responded = JOptionPane.showInputDialog(“Do you understand do while loops?”); boolean legitimate = false; do { String number = JOptionPane.showInputDialog(“Choose a number between 0 & 9 to generate \nthe corresponding word to that number or \npress 10 to exit the program”); switch(number) { case … Read more