Batch - If, ElseIf, Else

前端 未结 6 741
谎友^
谎友^ 2021-01-07 18:55

Whats wrong with this code?

IF \"%language%\" == \"de\" (
    goto languageDE
) ELSE (
    IF \"%language%\" == \"en\" (
    goto languageEN
) ELSE (
    ech         


        
6条回答
  •  甜味超标
    2021-01-07 19:16

    @echo off
    title Test
    
    echo Select a language. (de/en)
    set /p language=
    
    IF /i "%language%"=="de" goto languageDE
    IF /i "%language%"=="en" goto languageEN
    
    echo Not found.
    goto commonexit
    
    :languageDE
    echo German
    goto commonexit
    
    :languageEN
    echo English
    goto commonexit
    
    :commonexit
    pause
    

    The point is that batch simply continues through instructions, line by line until it reaches a goto, exit or end-of-file. It has no concept of sections to control flow.

    Hence, entering de would jump to :languagede then simply continue executing instructions until the file ends, showing de then en then not found.

提交回复
热议问题