My for try


he hinted about the magic numbers so i added a constexpr and called it world_length idk why that but apparently i don’t need that i can use the number 5 instead

(idk if i posted in the right place and the right sections,Sorry first time posting here)

The reason why is that at some point, your code might span several thousand lines. Looking for that one magic number that is causing unexpected behaviour is going to be very time consuming.

By the way, I noticed that you declare and initialize this constant integer two times;
constexpr int WORLD_LENGTH = 5
Once in main() and once inside the PrintIntro() function. You would benefit from declaring this once, and earlier in the program - try moving it to the top of yoiur main() function and removing it elsewhere, you’ll find that it works. The thing is to declare and initialize before you need it, and then rest assured that you have what you need when you do (saves you from repeating yourself). I hope this makes sense :slight_smile:

2 Likes

ty for passing by

Why does it need to be a constexpr instead of just initializing it normally…
IE:
int limit = 5;

Basically because we want to make sure that the value doesn’t get changed during run time, and to allow for compile time calculations, which have a positive impact on performance. Here’s a more in-depth explanation of constexpr: http://www.cprogramming.com/c++11/c++11-compile-time-processing-with-constexpr.html

Edit: cleaned up some missing spaces.

1 Like

this is my take of the For loop

Privacy & Terms