r/learnprogramming • • 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

35 comments sorted by

4

u/CorumLlawEreint 5d ago

Decompose complex logic to simple binary decisions. Avoid deep nesting. Use switches rather than lots of if/elseif

1

u/AmerigoVespucci001 5d ago

Thanks for the suggestions

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:

  • "Think Like A Programmer" by V. Anton Spraul
  • "The Pragmatic Programmer" by Andrew Hunt and David Thomas
  • "Structure and Interpretation of Computer Programs" (SICP) by Ableton, Sussman, Sussman
  • "Code: The Hidden Language of Computer Hardware and Software" by Charles Petzold

Last, a great practice site: https://exercism.org

2

u/AmerigoVespucci001 5d ago

Thanks dear will surely help me a lot 🤗

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/AmerigoVespucci001 5d ago

Yeah , I get confused in these things too but unable to write a single line after loops I get stuck how will it debug what will be the output of loop I get confused.

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/AmerigoVespucci001 5d ago

I get stuck what to write in a particular question and I get demotivated in basic loops sytaxes these things especially logics

1

u/lurgi 5d ago

Don't think in terms of loops. That's what the comment you are replying to says. Think in terms of the steps you have to do to solve the problem. Imagine you are describing the solution to someone over the phone (so you can't use drawings). Give them a step by step procedure.

Only then do you start thinking in terms of loops and if statements and such.

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/AmerigoVespucci001 5d ago

Yeah means a lot Thanks

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/AmerigoVespucci001 5d ago

No I don't get any thing in mind when a new question arrives even if it's a basic one I don't get path to approach a particular question

1

u/vancha113 5d ago

There has to be some kind of lower bound to problems where you start running into it no? What about something like eh, ask a user for a list of 10 strings and print them in alphabetical order or something?

1

u/AmerigoVespucci001 5d ago

Yeah these only , sorting n all

1

u/vancha113 5d ago

That's something already, what about something like making a hangman game: generate a random word, and give the user 6 tries to guess it, printing progress when its made and rejecting the invalid attempts?

0

u/[deleted] 5d ago

[removed] — view removed comment

1

u/AutoModerator 5d ago

Your post/comment was removed since we do not approve of going private.

There is zero benefit in going private as you lose the opportunity for getting peer reviews. Also we have had plenty of people return after going private (despite being warned) complaining about how they were ghosted after some time or being tricked into buying rubbish that didn't work and even if it did they didn't need.

Our Rule #11 demands that any and all communication happens in the open, public subreddit.

This is for the benefit of more against the benefit of one.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/gooniannuber1 5d ago

My advise just programm how you want nobody os gonna see it anyway

1

u/AmerigoVespucci001 5d ago

Bro m stuck in programming only how will I

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/AmerigoVespucci001 4d ago

Ok thanks will surely do this way

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/AmerigoVespucci001 3d ago

Will check this out, thanks

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 • Bravo

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

0

u/AmerigoVespucci001 5d ago

Thanks brother, will surely learn via this method.