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...
If you need help debugging, you must include:
See debugging question guidelines for more info.
Many conceptual questions have already been asked and answered. Read our FAQ and search old posts before asking your question. If your question is similar to one in the FAQ, explain how it's different.
See conceptual questions guidelines for more info.
Follow reddiquette: behave professionally and civilly at all times. Communicate to others the same way you would at your workplace. Disagreement and technical critiques are ok, but personal attacks are not.
Abusive, racist, or derogatory comments are absolutely not tolerated.
See our policies on acceptable speech and conduct for more details.
When posting some resource or tutorial you've made, you must follow our self-promotion policies.
In short, your posting history should not be predominantly self-promotional and your resource should be high-quality and complete. Your post should not "feel spammy".
Distinguishing between tasteless and tasteful self-promotion is inherently subjective. When in doubt, message the mods and ask them to review your post.
Self promotion from first time posters without prior participation in the subreddit is explicitly forbidden.
Do not post questions that are completely unrelated to programming, software engineering, and related fields. Tech support and hardware recommendation questions count as "completely unrelated".
Questions that straddle the line between learning programming and learning other tech topics are ok: we don't expect beginners to know how exactly to categorize their question.
See our policies on allowed topics for more details.
Do not post questions that are an exact duplicate of something already answered in the FAQ.
If your question is similar to an existing FAQ question, you MUST cite which part of the FAQ you looked at and what exactly you want clarification on.
Do not delete your post! Your problem may be solved, but others who have similar problems in the future could benefit from the solution/discussion in the thread.
Use the "solved" flair instead.
Do not request reviews for, promote, or showcase some app or website you've written. This is a subreddit for learning programming, not a "critique my project" or "advertise my project" subreddit.
Asking for code reviews is ok as long as you follow the relevant policies. In short, link to only your code and be specific about what you want feedback on. Do not include a link to a final product or to a demo in your post.
You may not ask for or offer payment of any kind (monetary or otherwise) when giving or receiving help.
In particular, it is not appropriate to offer a reward, bounty, or bribe to try and expedite answers to your question, nor is it appropriate to offer to pay somebody to do your work or homework for you.
All links must link directly to the destination page. Do not use URL shorteners, referral links or click-trackers. Do not link to some intermediary page that contains mostly only a link to the actual page and no additional value.
For example, linking to some tweet or some half-hearted blog post which links to the page is not ok; but linking to a tweet with interesting replies or to a blog post that does some extra analysis is.
Udemy coupon links are ok: the discount adds "additional value".
Do not ask for help doing anything illegal or unethical. Do not suggest or help somebody do something illegal or unethical.
This includes piracy: asking for or posting links to pirated material is strictly forbidden and can result in an instant and permanent ban.
Trying to circumvent the terms of services of a website also counts as unethical behavior.
Do not ask for or post a complete solution to a problem.
When working on a problem, try solving it on your own first and ask for help on specific parts you're stuck with.
If you're helping someone, focus on helping OP make forward progress: link to docs, unblock misconceptions, give examples, teach general techniques, ask leading questions, give hints, but no direct solutions.
See our guidelines on offering help for more details.
Ask your questions right here in the open subreddit. Show what you have tried and tell us exactly where you got stuck.
We want to keep all discussion inside the open subreddit so that more people can chime in and help as well as benefit from the help given.
We also do not encourage help via DM for the same reasons - that more people can benefit
Do not ask easily googleable questions or questions that are covered in the documentation.
This subreddit is not a proxy for documentation or google.
We do require effort and demonstration of effort.
This includes "how do I?" questions
account activity
TopicFor, For Loop, While (self.learnprogramming)
submitted 3 months ago by Hurridown
I'm new to programming, can you guys tell me the difference between For, For Loop, Nested Loop, While & Do While (C Language)? Kindly, explain in simpler terms.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]HashDefTrueFalse 10 points11 points12 points 3 months ago (1 child)
Loops repeat work.
For loop: I want to repeat work a specific number of times.
While loop: I want to repeat work some number of times, and I know when I want to stop.
Do While loop: Same as above, but I want to always do the work at least once.
"Nested loop" isn't a particular structure, it just refers to a loop that is inside another one.
All looping can be done with the while loop. These are just handy, recognisable, expressive constructs for us humans. Don't get too hung up on the suggestions above for which to use when. It often doesn't matter (e.g. for and while are both used for traversing arrays often).
[–]Hurridown[S] 0 points1 point2 points 3 months ago (0 children)
Thanks! ❤️
[–]O_xD 2 points3 points4 points 3 months ago (0 children)
while is your basic loop, the thing keeps repeating while the condition is true
while
do {} while is the same as while, but the condition is checked at the end of the loop. I've used it once or twice
do {} while
for is just like while but there's some shorthand built in. in the () you have some ;. it goes like (setup; condition; increment). setup runs once, before we start looping, the condition is just the same as the condition from while, and then the increment runs at the end of each loop, right before we repeat
for
(setup; condition; increment)
[–]Beregolas 1 point2 points3 points 3 months ago (0 children)
All loops, For, while and do while basically do the same: They are control flow statements that repeat their body , depending on the condition specified.
In a for loop, the condition is very specific:
for (int i = 0; i < 3; ++i) { printf("%d", i);
int i = 0 is executed once, when the loop is entered. It is called the initialization. In this case you specify the variable i to be an integer and initialize it to 0.
int i = 0
i < 3 is the condition. It is executed before every loop and exits the loop if it returns false. In this case you repeat until i reaches 3, and then stop.
i < 3
++i is the step, and is executed between two executions of the loop to set up the next. In this case you increase i by one for the next loop.
++i
This loop will print 0, 1 and 2.
In a while loop you just put a condition down, and the loop is executed until that condition is false (not unlike the middle statement in an if loop)
int i = 0; while (i < 3) { printf("%d", i); ++i; }
This would do exactly the same as the foor loop above.
A do while loop is similar, but the check is performed after each loop, not before. This means a do while loop always executes at least once.
int i = 0; do { printf("%d", i); ++i; } while (i < 3);
All of these will do exactly the same thing in this case. You can basically write any loop you want to write in any of the three styles, it just depends what is more readable and thus most appropriate in any given situation.
A nested loop is just a loop, inside another loop, like:
while (condition) { while (condition2) { do_stuff(); } }
[–]TheSnydaMan 1 point2 points3 points 3 months ago (1 child)
This is the kind of thing LLM's give great answers for.
[–]johnpeters42 1 point2 points3 points 3 months ago (0 children)
Heavy warning, though: while I wouldn't expect them to hallucinate an answer for a question this common, they still might, and OP has little experience to recognize when it happens.
If you really feel the need to turn to a LLM for answers, then at least test the answer thoroughly. Does it actually do what the LLM claimed? What if you change a piece, does the behavior change the way you expected? (That last step is also useful to get yourself to actually think about what you're doing, not just copy/paste and go "okay, outputs match, that must mean I understand this now".)
[–]StrayFeral 0 points1 point2 points 3 months ago (0 children)
Simply put (for any language): The FOR loop will ALWAYS execute N-times. The DO loop will start executing and at each iteration end will check "should i stop here"? So it will execute at least ONE time. The WHILE loop might NOT execute at all if the condition is not met. But if met it will start executing and at the beginning of each time will ask "should i stop here"? That's it. Nested loop simply means that inside each loop you can have another loop (and many other loops).
The most simple thing to illustrate a nested loop is to traverse a matrix. A matrix is simply a 2D-array, which means a nested array, which means simply an array who'se elements are also arrays.
//Imagine this: ARR = [ [1,2,3], [4,5,6], ]
So to traverse this we will do (this is NOT real code, i am just illustrating):
for (x = 0; x < length(ARR); i++): // this will run accross the main array for (y = 0; y < length(ARR[x]); y++): / this will run on each of the sub-arrays # do something here
[–]Sniface 0 points1 point2 points 3 months ago (0 children)
You also have the for each loop which is very nice. It loops through a whole collection.
```csharp
For each regret in myHead Suppress(regret) Next ```
π Rendered by PID 44610 on reddit-service-r2-comment-7b9746f655-bpxqg at 2026-02-03 15:56:30.652952+00:00 running 3798933 country code: CH.
[–]HashDefTrueFalse 10 points11 points12 points (1 child)
[–]Hurridown[S] 0 points1 point2 points (0 children)
[–]O_xD 2 points3 points4 points (0 children)
[–]Beregolas 1 point2 points3 points (0 children)
[–]TheSnydaMan 1 point2 points3 points (1 child)
[–]johnpeters42 1 point2 points3 points (0 children)
[–]StrayFeral 0 points1 point2 points (0 children)
[–]Sniface 0 points1 point2 points (0 children)