0

set goto=loop is supposed to change, so when it echos it, it should output "loop", but instead it still outputs "start". I can't seems to figure this one out.

set cash=100
set goto=start

if %cash% GEQ 100 (
    set /A cash=%cash%-100
    set %goto%=DEAD
    set goto=loop
    echo %goto%
    goto %goto%
) else (
    goto %goto%
)

1 Answers1

0

Your variable is changing within a code block, therefore you should be using delayed expansion of that variable:

Either:

@Echo Off
SetLocal EnableDelayedExpansion

Set "cash=100"
Set "goto=start"

If %cash% GEq 100 (
    Set /A cash=cash-100
    Set "%goto%=DEAD"
    Set "goto=loop"
    Echo !goto!
    GoTo !goto!
) Else (
    GoTo %goto%
)

  Or:

@Echo Off
SetLocal EnableDelayedExpansion

Set "cash=100"
Set "goto=start"

If %cash% GEq 100 (
    Set /A cash -=100
    Set "%goto%=DEAD"
    Set "goto=loop"
    Echo !goto!
    GoTo !goto!
) Else (
    GoTo %goto%
)

As with your earlier question please take a look at the usage information for the Set command, i.e. Set /?

Compo
  • 36,585
  • 5
  • 27
  • 39