![]() |
|
[Java] Changing my while loop to Do while loop - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] Changing my while loop to Do while loop (/showthread.php?tid=5794878) |
Changing my while loop to Do while loop - ohxerxe - Feb 4, 2018 Kind of a beginner here trying to turn a while loop program into a do while loop. Basically if you couldn't tell the program generates a number form 1-10 and the user has 3 attempts to guess. For my class we have to write it in a while loop and a do while loop. I have been looking around on the basic differences of do while and while and I think I understand the concept except I am almost lost on how to change this code or what parts to add to the Do section. I assume its simple and I am just not thinking properly. Only thing I have done was add the Do to the program without any statements or conditions. If anyone could push me in the right direction or convert it for me that would be greatly appreciated. Code import java.util.*;RE: Changing my while loop to Do while loop - Sheeple - Feb 4, 2018 It is quite simple :p do while's and while's in my eyes have always just been the exact same loop. You got it :D TBH it seems like you can C+P all your code into the do while without any major changes RE: Changing my while loop to Do while loop - ohxerxe - Feb 4, 2018 (Feb 4, 2018 01:53 PM)Sheeple Wrote: It is quite simple :p do while's and while's in my eyes have always just been the exact same loop. You got it :D That is what I had thought just not sure which parts to put under the do. It kind of pisses me off that the assignment instructions are so vague. (Feb 4, 2018 01:53 PM)Sheeple Wrote: It is quite simple :p do while's and while's in my eyes have always just been the exact same loop. You got it :D Thanks for the input I was able to do this and it works perfectly. I had a few issues with the formatting of the code but one that was fixed it works perfectly. Code import java.util.*;RE: Changing my while loop to Do while loop - matt - Feb 4, 2018 (Feb 4, 2018 01:53 PM)Sheeple Wrote: It is quite simple :p do while's and while's in my eyes have always just been the exact same loop. You got it :D While and do loops are not the same, a do loop is guaranteed to run at least once no matter what, a while loop the condition must be true in order for it to execute the loop. |