so i've created a for loop that calculates (x mod 6) + 2 for every number from 1-10 (inclusive), with "x" representing each individual number as the loop increments. however, i'd like to calculate the average for each of the 10 results, but i actually have no idea as to how i'd format the loop to do so. i'd rather not do something like echo "1 + 2 + 3 + etc"
as that seems extremely lazy and ill-constructed. i feel like this is something relatively easy, but i've tried searching it up and attempting another loop, but to no avail. any and all help is much appreciated!
here's the loop:
:ForLoop
@echo off &setlocal enabledelayedexpansion
echo This loop calculates the results for (x mod 6) + 2 with x being each number from1-10 (inclusive).
echo.
for /L %%x in (1, 1, 10) do (
SET /a VAR=%%x %% 6+2
set /a CAL=!VAR! %% 8
echo %%x MOD 6 + 2 = !CAL!
)
There's no need to do the
%% 8
jazz - sincevar
can only be (0..5)+2, this gives a range of 2..7.set /a
uses the run-time value of the variables, so!var!
is not required -%var%
would use the initial value ofvar
.Note that the average is truncated as batch does integer mathematics.