And thank you all before you even answer. So this is my first question in Stackoverflow.com i keep getting an error message saying "goto was unexpected at this time" i've searched for solution but i cant find anything. So if you know what im doing wrong tell me please :) im quite new to batch... im sorry if im doing really noobish mistake but i just cant tell whats wrong.
#echo off
:type
cls
echo %msg1%
echo %order%
choice /C abcdefghijklmnopqrstuvwxyz12 /n
if %errorlevel% == 28 goto save
if %errorlevel% == 27 goto varsave
if %errorlevel% == 26 goto set2
if %errorlevel% == 25 goto set2
if %errorlevel% == 24 goto set2
if %errorlevel% == 23 goto set2
if %errorlevel% == 22 goto set2
if %errorlevel% == 21 goto set2
if %errorlevel% == 20 goto set2
if %errorlevel% == 19 goto set2
if %errorlevel% == 18 goto set2
if %errorlevel% == 17 goto set2
if %errorlevel% == 16 goto set2
if %errorlevel% == 15 goto set2
if %errorlevel% == 14 goto set2
if %errorlevel% == 13 goto set2
if %errorlevel% == 12 goto set2
if %errorlevel% == 11 goto set2
if %errorlevel% == 10 goto set2
if %errorlevel% == 9 goto set
if %errorlevel% == 8 goto set
if %errorlevel% == 7 goto set
if %errorlevel% == 6 goto set
if %errorlevel% == 5 goto set
if %errorlevel% == 4 goto set
if %errorlevel% == 3 goto set
if %errorlevel% == 2 goto set
if %errorlevel% == 1 goto set
The only way to get goto was unexpected is an empty %errorlevel% variable. That should never happen. Are you sure, that you didn't set it manually somewhere in your code (something like set errorlevel=?
As others stated already, your construct with if %errorlevel% == xx should work fine. But you can dramatically shorten your code, because if errorlevel xx really means: "If errorlevel is xx or greater" (not like if %errorlevel% == xx, wich does a string comparison):
#echo off
:type
cls
echo %msg1% echo %order%
choice /C abcdefghijklmnopqrstuvwxyz12 /n
if errorlevel 28 goto save
if errorlevel 27 goto varsave
if errorlevel 10 goto set2
if errorlevel 1 goto set
Try it without the %s around ERRORLEVEL. And remove the ==s.
Related
i am trying to make character ("o") be able to enter both of the buldings, i've tried everything:
detecting %pos% so when its 5 it goes to :fishing store
adding "e" to choices so if i press e and %pos% equals 5 them goto :fishing store
(none of them worked, beacause i am doing something wrong and i don't know what)
ill be greatfull if someone will respond quickly
here is the code:
#echo off
title outside
mode 45,10
set/a pos=11
set "y7=[fishing] [ fanta's ]"
set "y6=[ store ] [ house ]"
set "y5=H-------H H---------H"
set "y4=H_II____H H_II______H"
set "y3=H___[ ]_H__o__H___[ ]___H__________"
set "y2=::::::::::::::::::::::::H\/\/H\/\/H"
set "y1=::::::::::::::::::::::::H/\/\H/\/\H~~~~~~~~~~"
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
goto movement
:movement
choice /c ad /n
if %errorlevel% equ 1 goto left
if %errorlevel% equ 2 goto right
:left
if %pos% gtr 1 set /a pos-=1
goto position
:right
if %pos% lss 32 set /a pos+=1
goto position
:position
if %pos% EQU 1 set "y3=o___[ ]_H_____H___[ ]___H__________"
if %pos% EQU 2 set "y3=Ho__[ ]_H_____H___[ ]___H__________"
if %pos% EQU 3 set "y3=H_o_[ ]_H_____H___[ ]___H__________"
if %pos% EQU 4 set "y3=H__o[ ]_H_____H___[ ]___H__________"
if %pos% EQU 5 set "y3=H___[o]_H_____H___[ ]___H__________"
if %pos% EQU 6 set "y3=H___[ ]oH_____H___[ ]___H__________"
if %pos% EQU 7 set "y3=H___[ ]_o_____H___[ ]___H__________"
if %pos% EQU 8 set "y3=H___[ ]_Ho____H___[ ]___H__________"
if %pos% EQU 9 set "y3=H___[ ]_H_o___H___[ ]___H__________"
if %pos% EQU 10 set "y3=H___[ ]_H__o__H___[ ]___H__________"
if %pos% EQU 11 set "y3=H___[ ]_H___o_H___[ ]___H__________"
if %pos% EQU 12 set "y3=H___[ ]_H____oH___[ ]___H__________"
if %pos% EQU 13 set "y3=H___[ ]_H_____o___[ ]___H__________"
if %pos% EQU 14 set "y3=H___[ ]_H_____Ho__[ ]___H__________"
if %pos% EQU 15 set "y3=H___[ ]_H_____H_o_[ ]___H__________"
if %pos% EQU 16 set "y3=H___[ ]_H_____H__o[ ]___H__________"
if %pos% EQU 17 set "y3=H___[ ]_H_____H___[o]___H__________"
if %pos% EQU 18 set "y3=H___[ ]_H_____H___[ ]o__H__________"
if %pos% EQU 19 set "y3=H___[ ]_H_____H___[ ]_o_H__________"
if %pos% EQU 20 set "y3=H___[ ]_H_____H___[ ]__oH__________"
if %pos% EQU 21 set "y3=H___[ ]_H_____H___[ ]___o__________"
if %pos% EQU 22 set "y3=H___[ ]_H_____H___[ ]___Ho_________"
if %pos% EQU 23 set "y3=H___[ ]_H_____H___[ ]___H_o________"
if %pos% EQU 24 set "y3=H___[ ]_H_____H___[ ]___H__o_______"
if %pos% EQU 25 set "y3=H___[ ]_H_____H___[ ]___H___o______"
if %pos% EQU 26 set "y3=H___[ ]_H_____H___[ ]___H____o_____"
if %pos% EQU 27 set "y3=H___[ ]_H_____H___[ ]___H_____o____"
if %pos% EQU 28 set "y3=H___[ ]_H_____H___[ ]___H______o___"
if %pos% EQU 29 set "y3=H___[ ]_H_____H___[ ]___H_______o__"
if %pos% EQU 30 set "y3=H___[ ]_H_____H___[ ]___H________o_"
if %pos% EQU 31 set "y3=H___[ ]_H_____H___[ ]___H_________o"
:fanta's house
cls
echo you are at fanta's house
pause
:fishing store
cls
echo you are at fishing store
pause
:print
cls
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
if %pos% EQU 5 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fishing store
if %pos% EQU 17 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fanta's house
if %errorlevel% equ 2 goto :left
if %errorlevel% equ 3 goto :right
goto movement
Firstly, make sure your file extension is .cmd and not .bat
Then something like this should help guide you.
Just replace your print section with this:
:print
cls
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
if %pos% EQU 5 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fishingstore
if %errorlevel% equ 2 goto :left
if %errorlevel% equ 3 goto :right
if %pos% EQU 17 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fantashouse
if %errorlevel% equ 2 goto :left
if %errorlevel% equ 3 goto :right
goto movement
As you seemed to have changed your original code, try this exact full version:
#echo off
title outside
mode 45,10
set/a pos=11
set "y7=[fishing] [ fanta's ]"
set "y6=[ store ] [ house ]"
set "y5=H-------H H---------H"
set "y4=H_II____H H_II______H"
set "y3=H___[ ]_H__o__H___[ ]___H__________"
set "y2=::::::::::::::::::::::::H\/\/H\/\/H"
set "y1=::::::::::::::::::::::::H/\/\H/\/\H~~~~~~~~~~"
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
goto movement
:movement
choice /c ad /n
if %errorlevel% equ 1 goto left
if %errorlevel% equ 2 goto right
:left
if %pos% gtr 1 set /a pos-=1
goto position
:right
if %pos% lss 32 set /a pos+=1
goto position
:position
if %pos% EQU 1 set "y3=o___[ ]_H_____H___[ ]___H__________"
if %pos% EQU 2 set "y3=Ho__[ ]_H_____H___[ ]___H__________"
if %pos% EQU 3 set "y3=H_o_[ ]_H_____H___[ ]___H__________"
if %pos% EQU 4 set "y3=H__o[ ]_H_____H___[ ]___H__________"
if %pos% EQU 5 set "y3=H___[o]_H_____H___[ ]___H__________"
if %pos% EQU 6 set "y3=H___[ ]oH_____H___[ ]___H__________"
if %pos% EQU 7 set "y3=H___[ ]_o_____H___[ ]___H__________"
if %pos% EQU 8 set "y3=H___[ ]_Ho____H___[ ]___H__________"
if %pos% EQU 9 set "y3=H___[ ]_H_o___H___[ ]___H__________"
if %pos% EQU 10 set "y3=H___[ ]_H__o__H___[ ]___H__________"
if %pos% EQU 11 set "y3=H___[ ]_H___o_H___[ ]___H__________"
if %pos% EQU 12 set "y3=H___[ ]_H____oH___[ ]___H__________"
if %pos% EQU 13 set "y3=H___[ ]_H_____o___[ ]___H__________"
if %pos% EQU 14 set "y3=H___[ ]_H_____Ho__[ ]___H__________"
if %pos% EQU 15 set "y3=H___[ ]_H_____H_o_[ ]___H__________"
if %pos% EQU 16 set "y3=H___[ ]_H_____H__o[ ]___H__________"
if %pos% EQU 17 set "y3=H___[ ]_H_____H___[o]___H__________"
if %pos% EQU 18 set "y3=H___[ ]_H_____H___[ ]o__H__________"
if %pos% EQU 19 set "y3=H___[ ]_H_____H___[ ]_o_H__________"
if %pos% EQU 20 set "y3=H___[ ]_H_____H___[ ]__oH__________"
if %pos% EQU 21 set "y3=H___[ ]_H_____H___[ ]___o__________"
if %pos% EQU 22 set "y3=H___[ ]_H_____H___[ ]___Ho_________"
if %pos% EQU 23 set "y3=H___[ ]_H_____H___[ ]___H_o________"
if %pos% EQU 24 set "y3=H___[ ]_H_____H___[ ]___H__o_______"
if %pos% EQU 25 set "y3=H___[ ]_H_____H___[ ]___H___o______"
if %pos% EQU 26 set "y3=H___[ ]_H_____H___[ ]___H____o_____"
if %pos% EQU 27 set "y3=H___[ ]_H_____H___[ ]___H_____o____"
if %pos% EQU 28 set "y3=H___[ ]_H_____H___[ ]___H______o___"
if %pos% EQU 29 set "y3=H___[ ]_H_____H___[ ]___H_______o__"
if %pos% EQU 30 set "y3=H___[ ]_H_____H___[ ]___H________o_"
if %pos% EQU 31 set "y3=H___[ ]_H_____H___[ ]___H_________o"
:print
cls
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
if %pos% EQU 5 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fishingstore
if %pos% EQU 17 choice /c ead /n >nul
if %errorlevel% equ 1 goto :fantashouse
if %errorlevel% equ 2 goto :left
if %errorlevel% equ 3 goto :right
goto movement
goto :EOF
:fantashouse
cls
echo you are at fanta's house
choice /c ce /m "Continue or exit?"
if %errorlevel% equ 2 goto :print
pause
goto :EOF
:fishingstore
cls
echo you are at fishing store
choice /c ce /m "Continue or exit?"
if %errorlevel% equ 2 goto :print
pause
goto :EOF
#ECHO OFF
SETLOCAL
title outside
rem mode 45,10
set/a pos=11
:position
set "y3=H___[ ]_H_____H___[ ]___H__________"
SET /a y7=pos+1
CALL SET "y3=%%y3:~0,%pos%%%o%%y3:~%y7%%%"
set "y7=[fishing] [ fanta's ]"
set "y6=[ store ] [ house ]"
set "y5=H-------H H---------H"
set "y4=H_II____H H_II______H"
set "y2=::::::::::::::::::::::::H\/\/H\/\/H"
set "y1=::::::::::::::::::::::::H/\/\H/\/\H~~~~~~~~~~"
cls
echo %y7%
echo %y6%
echo %y5%
echo %y4%
echo %y3%
echo %y2%
echo %y1%
:: goto movement
:movement
SET "choices=ad"
IF %pos% equ 5 SET "choices=ade"
IF %pos% equ 19 SET "choices=ade"
choice /c %choices% /n
if %errorlevel% equ 1 goto left
if %errorlevel% equ 2 goto right
IF %pos% equ 19 GOTO fanta's
IF %pos% equ 5 GOTO fishing
:left
if %pos% geq 1 set /a pos-=1
goto position
:right
if %pos% lss 32 set /a pos+=1
goto position
:fanta's house
cls
echo you are at fanta's house
pause
goto position
:fishing store
cls
echo you are at fishing store
pause
goto position
GOTO :EOF
A somewhat re-written version.
Since all that changes on the map is the position of o, place the o on the appropriate position on the line y3.
the first character in a string is "character 0" (hence, it's legitimate for pos to reach 0 - and gtr becomes geq in left:). Batch can substring using the syntax var:~start,length where start is the starting character number (or character-count from end, if negative) and length is number of characters (if negative, number of characters to not include).
So, we need to select that part of y3 from the start to pos, then the o and then the remainder of y3 starting at pos+1.
Hence - calculate pos+1 as batch can't apply a calculation in the substring formula and put the result in a temporary variable. I chose y7 since it's about to be reset anyway. and then use the parser to complete the extraction.
The parser examines CALL SET "y3=%%y3:~0,%pos%%%o%%y3:~%y7%%%" and replaces, left-to-right (let's assume pos=11, hence y7=12) %% with % and %var% with var's value since the set is being called:
set "y3=% y3:~0, 11 % o % y3:~ 12 %" (spaces inserted to show parser's steps)
set "y3=%y3:~0,11%o%y3:~12%" (as executed)
which places the o appropriately, depending on pos.
Our next step is whether o is at position 5 or 19 (not 17), when we need to allow e as well as a and d in the choice. Simply append the e in these circumstances, and choice will yield errorlevel 1 for a, 2 for d and 3 for e (but only if e is one of the choices).
Then - well, if choice has returned errorlevel 1 or 2, go left/right and if it's neither of those, then it must be 3, so e was pressed and we can look at pos to see which of the two routines to jump to.
Note that a label can't contain spaces, so if you tried fanta's house fanta's shop and fanta's tennis court then only the label fanta's would be interpreted (it's unusual, but not invalid, to use ' in a label). cmd would search for the next label fanta's following the goto as its destination, which might give the illusion of working correctly - but that's a trap...
#echo off
mode 1000
goto block1
:block1
echo color
goto block2
:block2
pause
set /a num=%random% %%5
goto 0
:0
if num == 0 goto a
goto 1
:1
if num == 1 goto b
goto 2
:2
if num == 2 goto c
goto 3
:3
if num == 3 goto d
goto 4
:4
if num == 4 goto e
goto 5
:5
if num == 5 goto f
goto 0
:a
color 0a
goto block2
:b
color 0b
goto block2
:c
color 0c
goto block2
:d
color 0d
goto block2
:e
color 0e
goto block2
:f
color 0f
goto block2
i want to make a color sign witch changes colors and i would like use simething like this . but i cant use else in batch and it would need something like that
From batch view point nearly all the gotos are useless and only
result in spaghetti code.
You are aware that a color stement will affect the whole screen?
%random% modulus 5 can only return 0..4
Your code shortened :
#echo off
mode 1000
echo color
:block2
pause
set /a num=%random% %%5
if %num% == 0 color 0a
if %num% == 1 color 0b
if %num% == 2 color 0c
if %num% == 3 color 0d
if %num% == 4 color 0e
goto block2
I made a parrot logo for an project and I want it to build before loading a basic trivia game I also made.
Whenever the image builds it closes when it finishes, I am unsure of how to make this work.
#echo off
cls
echo LOADING GAME...
ping localhost -n 5 >nul
#echo off
:loop
:menu
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0e
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu1
cls
color 0b
echo Trvia Game
ping localhost -n 5 >nul
color 0a
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu2
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0b
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu3
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0c
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu4
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0d
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:menu5
cls
color 0b
echo Trivia Game
ping localhost -n 5 >nul
color 0f
:loop
:menu
echo Made by River Davis
echo=================================================================================
echo 1)Start
echo 2)Options/Info
echo 3)exit
echo=================================================================================
set /p hi=
if not defined hi (
cls
goto loop
)
if %hi% == 1 goto Game
if %hi% == 2 goto Options/Info
if %hi% == 3 exit
:game
cls
echo What's Your Name?
set /p name=
echo Hello %name%! Would you like to start (y/n)
set /p start=
if %start% == y goto lvl1
if %start% == Y goto lvl1
if %start% == n goto menu
if %start% == N goto menu
goto start game
:Options/Info
cls
echo============================
echo This game was made for
echo Mrs.Crosby's class by
echo River Davis in 2016
echo============================
echo choose a Menu Colour
echo colours=0a,Light Green/ 0b,Light Aqua/ 0c,Light Red/ 0d,Light purple/
echo 0e,Light Yellow/ 0f,White
set /p color=
%color%
if %color%== 0a goto menu1
if %color%== 0b goto menu2
if %color%== 0c goto menu3
if %color%== 0d goto menu4
if %color%== 0e goto menu
if %color%== 0f goto menu5
:lvl1
cls
echo Question 1)
echo what does 1+2+3+4+5+6+7+8+9 equal
echo a.45
echo b.50
echo c.62
echo d.55
set /p ha=
if %ha% == a goto crl
if %ha% == b goto wrl
if %ha% == c goto wrl
if %ha% == d goto wrl
goto lvl1
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p ha=
if %ha% == y goto lvl2
if %ha% == Y goto lvl2
if %ha% == n goto lvl1
if %ha% == N goto lvl1
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl1
if %start% == Y goto lvl1
if %start% == n goto menu
if %start% == N goto menu
goto start game
:lvl2
cls
echo Question 2)
echo which planet is the 5th from the sun?
echo a.Venus
echo b.Jupiter
echo c.Uranus
echo d.Earth
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl2
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl3
if %hi% == Y goto lvl3
if %hi% == n goto lvl2
if %hi% == N goto lvl2
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl2
if %start% == Y goto lvl2
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl3
cls
echo Question 3)
echo which of the following colours has the most pigments?
echo a.Blue
echo b.Orange
echo c.Brown
echo d.Red
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto crl
if %hi% == d goto wrl
goto lvl3
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl4
if %hi% == Y goto lvl4
if %hi% == n goto lvl3
if %hi% == N goto lvl3
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl3
if %start% == Y goto lvl3
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl4
cls
echo Question 4)
echo who was the first man launched in to space?
echo a.Mike Collins
echo b.Neil Armstrong
echo c.Yuri gagarin
echo d.Buzz Aldrin
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto crl
if %hi% == d goto wrl
goto lvl4
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl5
if %hi% == Y goto lvl5
if %hi% == n goto lvl4
if %hi% == N goto lvl4
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl4
if %start% == Y goto lvl4
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl5
cls
echo Question 5)
echo Who was the Original owner of Apple?
echo a.Steve Jobs
echo b.Bill Gates
echo c.Jeorge Lucas
echo d.Harry Potter
set /p hi=
if %hi% == a goto crl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl5
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl6
if %hi% == Y goto lvl6
if %hi% == n goto lvl5
if %hi% == N goto lvl5
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl5
if %start% == Y goto lvl5
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl6
cls
echo Question 6)
echo Which of these deceased singers was assasinated?
echo a. Freddie Mercury
echo b. John Lennon
echo c. Elvis Presley
echo d. Michael Jackson
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl7
if %hi% == Y goto lvl7
if %hi% == n goto lvl6
if %hi% == N goto lvl6
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl6
if %start% == Y goto lvl6
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl7
cls
echo Question 7)
echo Who created the first light bulb?
echo a. Thomas Edison
echo b. Hiram Stevens
echo c. Joseph Swan
echo d. Albert Einstein
set /p hi=
if %hi% == a goto crl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl8
if %hi% == Y goto lvl8
if %hi% == n goto lvl7
if %hi% == N goto lvl7
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl7
if %start% == Y goto lvl7
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl8
cls
echo Question 8)
echo how old was Sir Edmund Hillary when he died?
echo a. 79
echo b. 92
echo c. 86
echo d. 88
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl9
if %hi% == Y goto lvl9
if %hi% == n goto lvl8
if %hi% == N goto lvl8
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl8
if %start% == Y goto lvl8
if %start% == n goto menu
if %start% == N goto menu
goto start game
#echo off
:lvl9
cls
echo Question 9)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl10
if %hi% == Y goto lvl10
if %hi% == n goto lvl9
if %hi% == N goto lvl9
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl9
if %start% == Y goto lvl9
if %start% == n goto menu
if %start% == N goto menu
:lvl10
cls
echo Question 10)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto crl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl11
if %hi% == Y goto lvl11
if %hi% == n goto lvl10
if %hi% == N goto lvl10
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl10
if %start% == Y goto lvl10
if %start% == n goto menu
if %start% == N goto menu
:lvl11
cls
echo Question 11)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto crl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl12
if %hi% == Y goto lvl12
if %hi% == n goto lvl11
if %hi% == N goto lvl11
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl11
if %start% == Y goto lvl11
if %start% == n goto menu
if %start% == N goto menu
:lvl12
cls
echo Question 12)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl13
if %hi% == Y goto lvl13
if %hi% == n goto lvl12
if %hi% == N goto lvl12
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl12
if %start% == Y goto lvl12
if %start% == n goto menu
if %start% == N goto menu
:lvl13
cls
echo Question 13)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl14
if %hi% == Y goto lvl14
if %hi% == n goto lvl13
if %hi% == N goto lvl13
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl13
if %start% == Y goto lvl13
if %start% == n goto menu
if %start% == N goto menu
:lvl14
cls
echo Question 14)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl15
if %hi% == Y goto lvl15
if %hi% == n goto lvl14
if %hi% == N goto lvl14
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl14
if %start% == Y goto lvl14
if %start% == n goto menu
if %start% == N goto menu
:lvl15
cls
echo Question 15)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto crl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl16
if %hi% == Y goto lvl16
if %hi% == n goto lvl15
if %hi% == N goto lvl15
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl15
if %start% == Y goto lvl15
if %start% == n goto menu
if %start% == N goto menu
:lvl16
cls
echo Question 16)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto crl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl17
if %hi% == Y goto lvl17
if %hi% == n goto lvl16
if %hi% == N goto lvl16
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl16
if %start% == Y goto lvl16
if %start% == n goto menu
if %start% == N goto menu
:lvl17
cls
echo Question 17)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl18
if %hi% == Y goto lvl18
if %hi% == n goto lvl17
if %hi% == N goto lvl17
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl17
if %start% == Y goto lvl17
if %start% == n goto menu
if %start% == N goto menu
:lvl18
cls
echo Question 18)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl19
if %hi% == Y goto lvl19
if %hi% == n goto lvl18
if %hi% == N goto lvl18
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl18
if %start% == Y goto lvl18
if %start% == n goto menu
if %start% == N goto menu
:lvl19
cls
echo Question 19)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto wrl
if %hi% == c goto wrl
if %hi% == d goto crl
goto lvl6
:crl
echo Correct!
echo.
echo Continue? (y/n)
set /p hi=
if %hi% == y goto lvl20
if %hi% == Y goto lvl20
if %hi% == n goto lvl19
if %hi% == N goto lvl19
goto crl
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl19
if %start% == Y goto lvl19
if %start% == n goto menu
if %start% == N goto menu
:lvl20
cls
echo Question 20)
echo INSERT QUESTION HERE
echo a. ANS
echo b. ANS
echo c. ANS
echo d. ANS
set /p hi=
if %hi% == a goto wrl
if %hi% == b goto crl
if %hi% == c goto wrl
if %hi% == d goto wrl
goto lvl6
:crl
echo Correct! Thanks For Playing! :)
pause
goto menu
:wrl
echo wrong
echo .
pause
cls
echo Retry? (y/n)
set /p start=
if %start% == y goto lvl20
if %start% == Y goto lvl20
if %start% == n goto menu
if %start% == N goto menu
#echo off
setlocal disableDelayedExpansion
set q=^"
echo(
echo(
call :c 0E " , .-;" /n
call :c 0E " , |\ / / __," /n
call :c 0E " |\ '.`-.| |.'.-'" /n
call :c 0E " \`'-: `; : /" /n
call :c 0E " `-._'. \'|" /n
call :c 0E " ,_.-=` ` ` ~,_" /n
call :c 0E " '--,. "&call :c 0c ".-. "&call :c 0E ",=!q!." /n
call :c 0E " / "&call :c 0c "{ "&call :c 0A "* "&call :c 0c ")"&call :c 0E "`"&call :c 06 ";-."&call :c 0E "}" /n
call :c 0E " | "&call :c 0c "'-' "&call :c 06 "/__ |" /n
call :c 0E " / "&call :c 06 "\_,\|" /n
call :c 0E " | (" /n
call :c 0E " "&call :c 0c "__ "&call :c 0E "/ ' \" /n
call :c 02 " /\_ "&call :c 0c "/,'`"&call :c 0E "| ' "&call :c 0c ".-~!q!~~-." /n
call :c 02 " |`.\_ "&call :c 0c "| "&call :c 0E "/ ' , "&call :c 0c "/ \" /n
call :c 02 " _/ `, \"&call :c 0c "| "&call :c 0E "; , . "&call :c 0c "| , ' . |" /n
call :c 02 " \ `, "&call :c 0c "| "&call :c 0E "| , , "&call :c 0c "| : ; : |" /n
call :c 02 " _\ `, "&call :c 0c "\ "&call :c 0E "|. , "&call :c 0c "| | | | |" /n
call :c 02 " \` `. "&call :c 0c "\ "&call :c 0E "| ' "&call :c 0A "|"&call :c 0c "\_|-'|_,'\|" /n
call :c 02 " _\ `, "&call :c 0A "`"&call :c 0E "\ ' . ' "&call :c 0A "| | | | | "&call :c 02 "__" /n
call :c 02 " \ `, "&call :c 0E "| , ' "&call :c 0A "|_/'-|_\_/ "&call :c 02 "__ ,-;` /" /n
call :c 02 " \ `, "&call :c 0E "\ . , ' .| | | | | "&call :c 02 "_/' ` _=`|" /n
call :c 02 " `\ `, "&call :c 0E "\ , | | | | |"&call :c 02 "_/' .=!q! /" /n
call :c 02 " \` `, "&call :c 0E "`\ \/|,| ;"&call :c 02 "/' .=!q! |" /n
call :c 02 " \ `, "&call :c 0E "`\' , | ; "&call :c 02 "/' =!q! _/" /n
call :c 02 " `\ `, "&call :c 05 ".-!q!!q!-. "&call :c 0E "': "&call :c 02 "/' =!q! /" /n
call :c 02 " _`\ ;"&call :c 05 "_{ ' ; "&call :c 02 "/' =!q! /" /n
call :c 02 " _\`-/__"&call :c 05 ".~ `."&call :c 07 "8"&call :c 05 ".'.!q!`~-. "&call :c 02 "=!q! _,/" /n
call :c 02 " __\ "&call :c 05 "{ '-."&call :c 07 "|"&call :c 05 ".'.--~'`}"&call :c 02 " _/" /n
call :c 02 " \ .=!q!` "&call :c 05 "}.-~!q!'"&call :c 0D "u"&call :c 05 "'-. '-..' "&call :c 02 "__/" /n
call :c 02 " _/ .!q! "&call :c 05 "{ -'.~('-._,.'"&call :c 02 "\_,/" /n
call :c 02 " / .!q! _/'"&call :c 05 "`--; ; `. ;" /n
call :c 02 " .=!q! _/' "&call :c 05 "`-..__,-'" /n
call :c 02 " __/'" /n
echo(
exit /b
:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b
:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^
^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
<nul set /p "=%DEL%%DEL%%DEL%"
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
)
)
if /i "%~3"=="/n" echo(
popd
exit /b
:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%temp%\'" set /p "=."
subst ': "%temp%" >nul
exit /b
:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b
I need the parrot to load first then the quiz, and every time I try combing them none of what I have tried has worked.
I am new to Batch and I would like to know if I can find out all combinations of numbers in order.
In this case I have 49 Numbers from 1 - 49 , and I have to pick 6 Numbers to be the results.
For example:
1 2 3 4 5 6
1 2 3 4 5 7
...
1 2 3 4 5 49
1 2 3 4 6 7
1 2 3 4 6 8
etc...
This is my old code:
#echo off > NEWFILE & setLocal EnableDelayedExpansion
set a=44
set b=45
set c=46
set d=47
set e=48
set f=49
for /L %%a in (1 1 !a!) do (
for /L %%b in (2 1 !b!) do (
for /L %%c in (3 1 !c!) do (
for /L %%d in (4 1 !d!) do (
for /L %%e in (5 1 !e!) do (
for /L %%f in (6 1 !f!) do (
echo.%%a %%b %%c %%d %%e %%f
))))))) >> NEWFILE
goto :EOF
However it returns:
1 2 3 4 5 6
1 2 3 4 5 7
...
1 2 3 4 5 49
1 2 3 4 6 6
Two 6's appeared.
I don't seem to be able to fix it, please help, thanks very much!
When you post a question you should post your efforts to solve it, describe the method used and the problems you had; otherwise you may get similar answers with no explanations at all, like this one:
EDIT: As users dbenham and aschipfl indicated, my original code have a small bug: the set /A i=M-1 line should be placed after the :nextSet label. This is the right code:
#echo off
setlocal EnableDelayedExpansion
set "N=%1"
set "M=%2"
set "line="
for /L %%i in (1,1,%M%) do (
set "C[%%i]=%%i"
set "line=!line! ^!C[%%i]^!"
)
:nextSet
set /A i=M-1
for /L %%j in (!C[%M%]!,1,%N%) do (
set "C[%M%]=%%j"
echo %line%
)
:nextPos
set "C=!C[%i%]!"
if %C% equ %N% (
set /A i-=1
if !i! equ 0 goto :EOF
goto nextPos
)
for /L %%i in (%i%,1,%M%) do (
set /A C+=1,C[%%i]=C
)
if !C[%M%]! gtr %N% goto nextPos
goto nextSet
Obviously, the corrected code generate a much larger number of results and this version is particularly slow... :(
The new version below use the exact same code of dbenham's solution; its only advantage is that you may change the parameters used to generate the result in a very easy way:
#echo off
setlocal EnableDelayedExpansion
set "N=%1"
set "M=%2"
set /A j=N-M, prev=0
set "for=" & set "line=" & set "endfor="
for /L %%i in (1,1,%M%) do (
set /A j+=1
set "for=!for! set /A start=!prev!+1 & for /L %%%%i in (^!start^!,1,!j!) do ("
set "line=!line! %%%%i"
set "endfor=!endfor!)"
set "prev=%%%%i"
)
REM ECHO !FOR! echo !LINE! %ENDFOR%
%for% echo %line% %endfor%
Output example:
C:\> test.bat 6 4
1 2 3 4
1 2 3 5
1 2 3 6
1 2 4 5
1 2 4 6
1 2 5 6
1 3 4 5
1 3 4 6
1 3 5 6
1 4 5 6
2 3 4 5
2 3 4 6
2 3 5 6
2 4 5 6
3 4 5 6
To get your results, use: test.bat 49 6
2ND EDIT: Faster method added
When the problem to solve is the excessive time a process takes, an obvious alternative is to use a faster programming language. The solution below use JScript, that is somewhat similar to Batch file programming:
#if (#CodeSection == #Batch) #then
#echo off
echo Start: %time%
cscript //nologo //E:JScript "%~F0" > result.txt
echo End: %time%
goto :EOF
#end
// JScript code section
for ( var A=1; A <= 44; ++A ) {
for ( var B=A+1; B <= 45; ++B ) {
for ( var C=B+1; C <= 46; ++C ) {
for ( var D=C+1; D <= 47; ++D ) {
for ( var E=D+1; E <= 48; ++E ) {
for ( var F=E+1; F <= 49; ++F ) {
WScript.Echo(A,B,C,D,E,F);
}
}
}
}
}
}
This is a Batch-JScript hybrid script; save it with .BAT extension. This program took a little less than 9 minutes in my cheap-and-slow lap-top computer to generate a 239 MB file with 13983816 lines.
The problem is compute intensive, given that there are 13,983,816 unique permutations. (See https://en.wikipedia.org/wiki/Lottery_mathematics#Calculation_explained_in_choosing_6_from_49.)
The Rojo answer should work, but the GOTO and repetitive FOR /F parsing and IF logic will slow things down considerably.
The code is much faster if you use nested FOR /L loops.
#echo off
setlocal enableDelayedExpansion
for /l %%A in (1 1 44) do (
set /a start=%%A+1
for /l %%B in (!start! 1 45) do (
set /a start=%%B+1
for /l %%C in (!start! 1 46) do (
set /a start=%%C+1
for /l %%D in (!start! 1 47) do (
set /a start=%%D+1
for /l %%E in (!start! 1 48) do (
set /a start=%%E+1
for /l %%F in (!start! 1 49) do (
echo %%A %%B %%C %%D %%E %%F
)
)
)
)
)
)
This will still be unbearably slow to let this script print the results to the screen. I estimate it will take 1.25 hours on my machine. Redirecting the output to a file is about 5 times faster, around 15 minutes.
In the future, please show some code demonstrating that you've attempted to solve the problem yourself, showing where you got stuck, where the output is not as expected, etc. Questions resembling "Here are my requirements. Code this for me" generally aren't well-received around here. How you got an upvote without showing any code is beyond me, but c'est la vie.
In this instance, I found the problem interesting, so I thought I'd go ahead and get you started. Challenge: accepted. Here's one way to do it.
#echo off
setlocal enabledelayedexpansion
set "series=1 2 3 4 5 6"
:loop
echo %series%
if "%series%"=="44 45 46 47 48 49" goto :EOF
for /f "tokens=1-6" %%a in ("%series%") do (
set /a i1=%%a, i2=%%b, i3=%%c, i4=%%d, i5=%%e, i6=%%f+1
if !i6! gtr 49 set /a i5+=1, i6=i5+1
if !i5! gtr 48 set /a i4+=1, i5=i4+1, i6=i5+1
if !i4! gtr 47 set /a i3+=1, i4=i3+1, i5=i4+1, i6=i5+1
if !i3! gtr 46 set /a i2+=1, i3=i2+1, i4=i3+1, i5=i4+1, i6=i5+1
if !i2! gtr 45 set /a i1+=1, i2=i1+1, i3=i2+1, i4=i3+1, i5=i4+1, i6=i5+1
set "series=!i1! !i2! !i3! !i4! !i5! !i6!"
)
goto loop
Here's another solution that should be more efficient.
#echo off
setlocal enabledelayedexpansion
set "series=1 2 3 4 5 6"
set total=0
for /L %%a in (1,1,44) do (
set /a i2 = %%a + 1
for /L %%b in (!i2!, 1, 45) do (
set /a i3 = %%b + 1
for /L %%c in (!i3!, 1, 46) do (
set /a i4 = %%c + 1
for /L %%d in (!i4!, 1, 47) do (
set /a i5 = %%d + 1
for /L %%e in (!i5!, 1, 48) do (
set /a i6 = %%e + 1
for /L %%f in (!i6!, 1, 49) do (
rem // Uncomment this echo to watch the progress (severely decreases efficiency)
rem echo %%a %%b %%c %%d %%e %%f
set /a total += 1
)
)
)
)
)
echo Total so far: !total!
)
rem // Should have gone through 13983816 iterations
I am trying to work with negative numbers, but obviosly I am doing something stupid.
The attached script will always display:
testA = 15
testB = -15
testA GTR 0
testA GEQ 0
testB GTR 0
testB GEQ 0
Until now i was under the impression that -15 is <= 0.
What am I doing wrong?
Batch script:
#echo off
set /a testA = 15
set /a testB = -15
echo testA = %testA%
echo testB = %testB%
echo(
if %testA% GTR "0" echo testA GTR 0
if %testA% GEQ "0" echo testA GEQ 0
if %testA% LEQ "0" echo testA LEQ 0
if %testA% LSS "0" echo testA LSS 0
echo(
if %testB% GTR "0" echo testB GTR 0
if %testB% GEQ "0" echo testB GEQ 0
if %testB% LEQ "0" echo testB LEQ 0
if %testB% LSS "0" echo testB LSS 0
echo(
pause
You are indeed right. The Association of Mathematical Bods has not enacted any recent changes to the laws governing sequencing of integers, so your problem must lay elsewhere :-)
In fact, it's the " quote marks around your 0 values that is causing this problem. Get rid of them. When you do so, you get the rather more sensible output of:
testA = 15
testB = -15
testA GTR 0
testA GEQ 0
testB LEQ 0
testB LSS 0
The reason your "0" case doesn't work if because gtr and associated operators are actually string comparisons rather than numeric ones. The reason they work for numerics is buried deep within the help for the if statement:
These comparisons are generic, in that if both string1 and string2 are both comprised of all numeric digits, then the strings are converted to numbers and a numeric comparison is performed.
Since " can in no way be considered a "numeric digit", the comparison performed was a string-based one and, in ASCII, " (code point 0x22) is less than any digit (0x30 through 0x39) or the - sign (0x2d) in the case of testB.