Wednesday, 4 October 2023

Do we really understand how loops work?


                                Particularly in programming!



Back in 2014 when I used to take my programming classes, I spent around one and a half months just understanding how loops work. That includes printing out different patterns, cascading loops and looking at how memory is updated at each level of loop with only pen and paper, no digital device allowed!


From past few years, one thing is kept bothering me which is the “programming tutorials” on the YouTube.com teaching everything in just 5 minutes. I was like, how is this even possible that you can understand something in just 5 minutes?


These presenters say that a loop is something that repeats for a certain amount of time. Even they do use the word iterate sometimes, but they claim that it means the same as repeat.

Which isn't true at all, what I remembered, if I am correct. The meaning of the word Iterate means that – keep doing the task with the updated value to achieve the truth at the end, meanwhile repeat means keep doing the same thing with no change.

I found this just now to again verify my claim at English Stack Exchange -

"Iteration" comes from the Latin "iter" meaning "journey". Iteration is performing the same task at different places or with different circumstances as part of a longer sequence. It is not doing the exact same thing (that would be reiteration - to repeat a journey). The word "Iteration" always conveys the sense of progress, improvement, growth or change.

Repetition, on the other hand, is to perform the exact same action, with no change of circumstance. Unlike "Iteration", "Repetition" does not suggest progress or movement forwards.


Life and loops are similar in terms of initiation, maintenance, and termination.

  • Initiation is starting at a point and maintaining ourselves.
  • Maintenance is keeping healthy and working to avoid getting stuck.
  • Termination is the final stage of a loop.
  • Iterations or repetitions in a loop can involve using different values each time.


Initialization, Maintenance, and Termination are the three properties of a loop.
  • Initialization is the starting point of the loop.
  • Maintenance is the process of iteration in the loop.
  • Termination is the condition that ends the loop.


Induction is the process of integrating or inducing an idea.

  • In induction, the truth value of a base is used to project outcomes.
  • Induction can be encountered in college admissions or choosing a major.
  • Induction is similar to iteration or integration with different values.


Loop and induction have a crucial difference

  • Loop does not use mathematical induction
  • Induction involves proving something step by step

State machine and mathematical induction are different because state machine is finite while mathematical induction is not.

  • The state machine terminates and is finite, just like us.
  • Mathematical induction is not finite and does not end.
  • State machine can be proven through experience and achievements.
  • Looping and maintaining a base is crucial in state machine.
  • Mathematical induction is different from Marvel's explanation of Quantum.


Explanation of insertion sort using playing cards

  • The book uses the example of playing cards to explain the loop used in insertion sort.
  • The choice of playing cards as an example highlights the thought process of the writers.
  • The authors were philosophical in selecting the card example.
  • The card example is common worldwide and has two colors – red and black.
  • The use of red and black in the example is influenced by the black and white screens used in older days.
  • Insertion sort is an in-place sorting algorithm that sorts values by inserting them in their correct position.


Sorting a deck of cards in a game

  • The players couldn't figure out the rules of the game
  • They randomly started sorting the cards
  • They ended up with a complete sorted deck of 52 cards
  • The ability to sort the deck determined the outcome of the game

The example is taken from the book CLRS.


Meanwhile, the video which I recorded explaining what and how loops precisely works. 


In short, loops are nothing but finite Mathematical Induction.


LibreOffice Google Summer of Code Final Report

Adding native support for histogram chart and its variations  My final report for the work done since May till August in LibreOffice codebas...