dT{GetFrameTime()} question

I have a question about creating this variable. I’m curious the reason behind creating it as a constant in the loop? Does this not recreate this variable from scratch every single time through the loop? If so, what cleans up the old copy? Why is this a better solution than creating the variable outside the loop (as just a float, not a const float because the value needs to be able to change) and then having it grab the GetFrameTime value each iteration of the loop? Just looking to understand the thought process…

The reason we make it a const float is because we want to prevent other code from accidentally modifying the value store in dT somewhere else. With the variable being const we would get a compiler error if our code was unintentially attempting to modify the value store.

This also means that we need to set the initial value of dT at the time of declaration, so if we set it outside the loop it won’t ever change.

When inside of the loop, think of the process like doing arts and crafts at your kitchen table. Once you’re done building something, you then immediately clean the table before going to the next craft to be made using the same process.

To bring the analogy to your code, both the compiler and the Operating System executing the code will manage the cleaning and recreation of declared variables in memory as they go in and out of scope or when a loop starts up again.