This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
My teacher wants us to enforce having one entry and one exit in a program. What do I put on that line to have the loop restart? Because you want to continue the program, but you didn't supply a name last time, so it can't drop down to the Output box. break; only exits the program.
Have you been specifically told that you have to put something on line 18 ? Because the way I'd do it is to put an else on line 21 (so that it didn't print Hello null) and then delete lines 15 - 18.
I'd also change line 12 to
if(usrOption == JOptionPane.YES_OPTION)
as it makes the code a lot clearer and you then no longer need the comment.
Joined: Jan 17, 2013
Jesper de Jong wrote:
You can also put continue; at line 18; then the program will immediately jump to line 7 for the next iteration (skipping the rest of the loop body, so line 22 will not be executed).
Thank you, i have been looking for a while something that restarts a loop.
Note: The continueLoop variable in your code isn't doing anything useful. Note that the break; in line 15 jumps out of the loop, no matter what the value of continueLoop is.
But the break isn't hit until you say you want to exit the application. without the break and the continueLoop this wouldn't work.