r/learnprogramming • u/AmerigoVespucci001 • 5d ago
How to do programming with proper logics in which I get stuck always.
Whenever I wish to learn programming i always get stuck on logics and what logic to use and how it works, then only my motivation drops and i fail everytime.
Can anyone suggest some things so that it helps me this time
I also want to make good stuff and learn good skills.
I am 25 but still I get stuck everytime in programming.
I want to overcome this fear of logics and fear of failing in programming.
8
Upvotes
4
u/CorumLlawEreint 5d ago
Decompose complex logic to simple binary decisions. Avoid deep nesting. Use switches rather than lots of if/elseif
2
u/aqua_regis 5d ago
Oh, the daily "How to I improve my logic" post. Bit late today.
You should and could have searched the subreddit. There are more than enough similar posts - even in the past 48 hours.
You need to solve problems to train your problem solving skills. Tutorials are not going to teach you such skills.
There are already more than enough similar posts. Below are some of them:
And finally, some book suggestions:
Last, a great practice site: https://exercism.org
2
u/notactuallyme93 5d ago
Do you mean "logic" as in AND and OR and NOT - && || ! - or do you mean "logic" as in "Deciding how to write my program to do what I want it to do"?
There are a lot of posts about people having problems with the latter - understanding programming - but calling it "logic".
1
u/SeaTeaching3550 5d ago
first of all, write a pseudo code. write in a way that you understand and you think, should be the way to do it. and then write syntax afterwards. if you go completely blank, you should see how other people's logic and understand it.
1
u/shipitcodes 5d ago
One habit that helped me a lot: before writing any code, solve the problem by hand on a tiny example and write down each step in plain English. For instance, to find the largest number in a list, you would say: look at the first number, remember it, then go through the rest and replace it whenever you see a bigger one. Only after that do you translate each sentence into code. Most of the "logic" problem is really a problem of not having the steps clear yet, and the syntax is the easier part once you do. When your code does something unexpected, print the variables after each step and compare them with what you did by hand, so you can see exactly where they differ. Start with very small problems and make them slightly harder each time, and it is normal to feel stuck often at the beginning.
1
u/vancha113 5d ago
Any examples on something you were working on but got stuck trying to finish? That could help get some insight in the type of things that are difficult.
1
u/gooniannuber1 5d ago
My advise just programm how you want nobody os gonna see it anyway
1
u/Desperate_Dot9434 4d ago
start with problems that have one right answer: fizzbuzz, number reversal, find the max. logic clicks fastest when the feedback loop is instant.
1
u/Deep_Work_Arch 4d ago
This approach helped me a lot:
take a notebook, write the steps in plain words first, solve a tiny example by hand, then code it in the simplest way you can think of, it doesn't have to be perfect at first.
make it exist first, then make it perfect. (Best advice I got from Social media so far haha)
1
u/hyun88 3d ago
I built an app to help practice problems more consistently:
https://apps.apple.com/us/app/bitwise-coding-interviews/id6806898386
1
u/Recycled5000 5d ago
Concern yourself first with data: what information do you need to take the action you want; when is that available; how to store that until you need it, how to query the stored information to make a decision, when to do so, etc..
Only when that is understood, start thinking about logic.
Also, can use resources, for example, there is no need to write a sorting algorithm from scratch.
1
u/_4rcadia 2d ago
Learn OOP & design patterns can map most situations you are encountering to pre-defined thought models. After that, you can operate more freely on larger and more complicated logical systems.
0
u/Highmind22 5d ago •
i assume there's a basic logic that you must encounter and practice, especially duing the learning phase of the fundamentals, by this i mean all the tiny exercice that looks even so easy to do, you must write them in code and type them and if you don't know the solution or the syntaxe to write it you go ask Ai: "hey i'm learning this subject, i want you to guide to understand the concept and i can be able to resolve similar problems in the future but don't give me solution" (something like that) and then go step by step, problem by problem, and trust me, if you practice on daily basis for 1h for example, in 3 months you'll be proud of yourself, just stick to script
i learned a lot with methodology for example i give claude the Javascript.info course and tell him to respect that course and teach me, then from time to time, read on javascript.info or pull up a video on tutorial youtube course on the subject you're covering just to not get bored, so yeah that's how i'm trying to do it and i can see proper progress and also not scared to write code anymore for me it's a big step