Wednesday 16 November 2022

Chapter 25 // Exercise 5, 6 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 25 // Exercise 5

Write an infinite loop. Execute it.


Simple enough.

Chapter 25 // Exercise 6

Write an infinite loop that is hard to recognise as an infinite loop. A loop that isn't really infinite because
it terminates after completely consuming some resource is acceptable.


For this one I immediately though of a for loop going backwards but checking if the index was >= 0 (I'm not proud to say I've done this before...). However, Visual Studio is very smart these days and will give you an intellisense warning that the loop is infinite.

It also does the same for the old if(bool = false). I even googled for one but VS even recognised that as infinite. The best way to do it would be to just allocate memory in a recursive function.

No comments:

Post a Comment