Is a clock a real life example of a nested loop?

So , I was thinking about nested loops and it cross my mind , that clocks like the ones you can see in the picture might be a real life example of a nested loop. What do you think?

The first and outside loop would be the seconds pointer , which after 1st completion moves the inside loop : minutes pointer.

Then , after minutes pointer 1st completion , we movesthe hour pointer , which loops inside minute loop.

1 Like

From a basic standpoint you could probably say that, however I would say it depends on the type of clock.

An analog clock, like your picture above, I would not consider a nested loop due to the way it moves. Let’s take a look at a nested loop:

const set1 = [1, 2, 3];
const set2 = [1, 2, 3];

for (let i = 0; i < set1.length; i++) {
  for (let j = 0; j < set2.length; j++) {
    console.log(set1[i], set2[j]);
  }
}

OUTPUT:

1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

This has a specific set of points which are displayed.
However since an analog clock’s hands move at a steady pace based on the rotation of its gears, its hands will end up in places that are between two set points.

A digital clock may be more like a nested loop, since the numbers being displayed will be exact points.

These are just my thoughts on the matter.

I don’t think that is how clocks work. From what I read about clocks in programming, is that they use reference points (January first 1970 for *nix systems and January first 1980 for windows systems)

this creates a timestamp (the amount of seconds which have passed since reference point), which is then converted to human friendly format using math.

This results in a single loop, which can handle incrementing the timestamp/seconds and convert the timestamp to a human friendly format

I am very likely over simplifying a lot here. But this is my 2 cents.

1 Like

Absolutely! @stetim94 and @8-bit-gaming are right that in an actual programming sense they wouldn’t be in an implementation.

But as a concept they absolutely are! And analogue clocks have one gear as the nested loop and every full rotations knocks the minute gear on by one etc.

We can take this a step further and say that clocks are just a form of counting system. And if we think about it like that numbers themselves are a really world example of nested loops… move your digits ten places and it changes the tens column by one, cool right.

You can see a really sweet example of this in binary (base 2) https://youtu.be/zELAfmp3fXY

1 Like