-
Notifications
You must be signed in to change notification settings - Fork 64
/
ds-sets-2.bat
64 lines (49 loc) · 1.1 KB
/
ds-sets-2.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@echo off
::
:: The Batchography book by Elias Bachaalany
::
setlocal enabledelayedexpansion
set NUMSET=5 1 10 95 17
set PLANETSET=Mars Jupiter Pluto Earth Saturn
call :test-contains
goto :eof
:test-contains
:repeat-n-set
set /P N=Enter a number to see if it is in the set:
call :set-contains NUMSET %N%
if %errorlevel% EQU 1 (
echo '%N%' is in the set!
) else (
echo '%N%' is NOT in the set!
goto repeat-n-set
)
:repeat-p-set
set /P P=Enter planet name to see if it exist in the set:
call :set-contains PLANETSET %P%
if %errorlevel% EQU 1 (
echo '%P%' is in the set!
) else (
echo '%P%' is NOT in the set!
goto repeat-p-set
)
goto :eof
:set-contains <1=Set name> <2=Value>
call set __V=%%%~1%%
for %%a in (%__V%) do (
if %%a EQU %~2 (
exit /b 1
)
)
set __V=
exit /b 0
goto :eof
:set-remove <1=Set name> <2=Value>
:: Exercise for the user
echo NOT IMPLEMENTED
goto :eof
:set-add <1=Set name> <2=Value>
:: Exercise for the user
echo NOT IMPLEMENTED
goto :eof
:set-destroy <1=Set name>
set %~1=