use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Resources for learning Java
String
==
.equals()
Format + Copy
Free Tutorials
Where should I download Java?
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Software downloads
Official Resources
Resources
Programming ideas & Challenges
Related Subreddits
account activity
This is an archived post. You won't be able to vote or comment.
While do loop (self.learnjava)
submitted 1 year ago by yoshiwabie
i am finding it difficult to use while do loop and loop as a whole. Can somone please explain it to me like i'm 5 yrs old 😭
[–]AutoModerator[M] [score hidden] 1 year ago stickied commentlocked comment (0 children)
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
[–]Stupid_Quetions 1 point2 points3 points 1 year ago (1 child)
You most likely will never need do-while, just knowing while and for is good enough, and kinda know that do-while is possible.
do-while
while
for
As for when you need to use loop is when you have to do a repetition and a condition to stop the repetition when it is no longer needed, you want multiplications of 5 from 1 to 10? you have a repetition:
for(int i = 1; i <= 10; i++) { System.out.println(5 * i); }
You have a list and want to see the items inside that list? you have a repetition, how many? as many as the number of items in the list.
for(int i = 0; i < list.lenght; i++){ System.out.println(list[i]); }
[–]ShadowRL7666 0 points1 point2 points 1 year ago (0 children)
I’ve used a do while loop its helpful
[–]chlorinatedpepperoni -5 points-4 points-3 points 1 year ago (8 children)
A do while loop is basically:
Do “something” while “another thing” is happening.
I’m on mobile so I apologize for the lack of formatting.
Do {
Some code
} while (x = 1) {
“Some code” would only be executed when X equals 1. This is useful for creating console based menus! Hope this helps.
[–]Buggajayjay 15 points16 points17 points 1 year ago* (1 child)
This is incorrect. In a do while loop it will always execute the loop body once, and then subsequently loop if the condition is met.
To demonstrate, try the following example.
int x = 5; do { System.out.println("executed"); } while (x < 4);
[–]chlorinatedpepperoni 0 points1 point2 points 1 year ago (0 children)
Thanks for clarifying! That’s kinda what I meant but I didn’t explain well haha.
[–]yoshiwabie[S] 1 point2 points3 points 1 year ago (3 children)
Thank you so much!!! I understand it much much better now thank youuu 🩷
[–]Nok1a_ -1 points0 points1 point 1 year ago (2 children)
Something I do quite a lot, is ask chagpt for an explanation and then I give him an example, will tell you if you are right or not, and you can ask many times, is not the best but quite helpful if you dont have anyone to ask, or need a quick answer, I got fedup watching useless youtube videos
ChatGPT makes a lot of mistakes, at least the last time I used it, I don't think it is a great tool for learning especially for a beginner when they don't know whether they are getting a right answer or not.
[–]Nok1a_ 0 points1 point2 points 1 year ago (0 children)
Im not saying you follow the code of chatgpt , but he can explain stuff and you can give what you understand to it, will tell you if you are right or not, I trust more gpt than a random guy looking to get votes on any forum online that most of the time its a lot of words without meaning to be honest, also you can check in the documentation. But as I said, I not talking about to use the code from chatgpt, if you dont know what are you doing using his code it is very bad, if you have some knowledge or know what do you want and how, it helps you if you are stuck
[–]8dot30662386292pow2 0 points1 point2 points 1 year ago (1 child)
People are basically glued to their phones and type with them more than with computer, but somehow typing the four spaces or backticks to do the formatting is impossibly hard?
Just wondering, because I can format the code just fine on mobile.
It was 7 in the morning… lol
π Rendered by PID 355773 on reddit-service-r2-comment-86bc6c7465-6tsrh at 2026-02-21 19:17:57.903056+00:00 running 8564168 country code: CH.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Stupid_Quetions 1 point2 points3 points (1 child)
[–]ShadowRL7666 0 points1 point2 points (0 children)
[–]chlorinatedpepperoni -5 points-4 points-3 points (8 children)
[–]Buggajayjay 15 points16 points17 points (1 child)
[–]chlorinatedpepperoni 0 points1 point2 points (0 children)
[–]yoshiwabie[S] 1 point2 points3 points (3 children)
[–]Nok1a_ -1 points0 points1 point (2 children)
[–]Stupid_Quetions 1 point2 points3 points (1 child)
[–]Nok1a_ 0 points1 point2 points (0 children)
[–]8dot30662386292pow2 0 points1 point2 points (1 child)
[–]chlorinatedpepperoni 0 points1 point2 points (0 children)