In programming, the module is useful for storing numbers in a range not exceeding the upper limit of the boundary.
For instance:
int value = 0;
for (int x=0; x<100; x++)
cout << value++%8 << " ";
Output:
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7...
Now consider this situation:
int value = 5;
for (int x=0; x<100; x++)
cout << value-- << " ";
Output: 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7...
My question is: how to set the lower limit to 0 WITHOUT using any conditional statement like if or switch case?
The output I want: 5 4 3 2 1 0 0 0 0 0 0 0 ...
source
share