Quote:
do you memorize the codes you write or you just pick it from any place and you write it.
Your question is not very clear, but I think I understand what you want.
A programming language purpose is to translate an algorithm to plain text in a way that will allow a computer to execute that algorithm once compiled.
Thus a programming language have only very little number of structures, just enough to translate an algorithm.
So what is important is the starting point, the algorithm.
The part of writing the code is deduced from the algorithm, the algorithm tells you when you need a loop or an alternative, and how you need them.
So the key of writing code is your understanding of algorithm.
- Learn one or more analyze methods, E.W. Djikstra/N. Wirth
Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[
^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[
^]
https://en.wikipedia.org/wiki/Structured_programming[
^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[
^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[
^]
- Learn Algorithms and Data-Structures (many books exist).