Search code examples
batch-filegoto

Double GOTO Command - DOS-Based Clock


I'm making a DOS-Based clock with blinking black/white background every seconds but goto command can't use like the code below the first goto makes the command runs only in the :CLOCK label can anyone help me about this?

@echo off 
title DOS-Based Clock 
color a 
cls
goto CLOCK
goto 0a
:CLOCK
cls
echo The current time is: %time%
goto CLOCK
:0a
color 0a
ping -n 2 127.0.0.1>nul
goto 7a
:7a
color 7a
ping -n 2 127.0.0.1>nul
goto 0a

Solution

  • @echo off 
        title DOS-Based Clock 
        set "color=0a"
    
    :clock
        cls
        color %color%
        echo the current time is: %time%
    
        ping -n 2 127.0.0.1 > nul
        goto %color%
    
    :0a
        set "color=7a"
        goto clock
    
    :7a
        set "color=0a"
        goto clock
    

    Use a variable to store the color and use it both to change the color and to jump to the same label as the color, then change the value of the color and repeat the process