Batch programming code explanation needed -


i'm trying understand batch script found online , code designed check last day of month , terminate script if condition true.

heres copy of code.

rem @echo off /f "tokens=1,2,3 delims=/ " %%a in ('echo %date%') set day=%%a & set month=%%b & set year=%%c  set /a leap=%year% %% 3 if %leap%==0 (set eom=29) else (set eom=28)  echo 01 03 05 07 08 10 12 | find "%month%" > nul && set eom=31 echo 04 06 09 11 | find "%month%" > nul && set eom=30  rem if %eom%==%day% exit 

however understand rest of code except following 2 lines.

set /a leap=%year% %% 3 if %leap%==0 (set eom=29) else (set eom=28) 

when i've tried echo contents of leap variable keep getting 2, if i'm honest don't understand how ever 0 ?

any advice on helpful.

%% means modulus, since each leap year 4 years apart e.g. 2012(leap),2013,2014,2015,2016(2nd leap), if value of leap year 0, value of last year before leap year 4.( think of array, [0,1,2,3,5], 0 4 5 numbers apart). , so, 2016 leap year, since value 4 5th number 0.

if still confused why modulo 4? because leap year divided 4 0, said before, 0 means leap year.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -