Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 330 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Counter" in Batch

#1
I'm trying to make a Batch file that will increment a variable by 1 each time it loops, and then check if the variable is equal to 5, and if it isn't, it loops again. I know there's probably a while loop for this, but I didn't know how to do that, and I'm just enjoying learning Batch for fun right now

Here's the code, it doesn't work the way it should, it just displays a 0: and then does nothing else. So how would I go about fixing it? I have a feeling I'm setting and incrementing the variable wrong, and maybe it's confused about the 2 if statements? (Does it have an else if....?) Anyways, thanks for the help

@echo off
set /p i=0:
goto A

:A
set /p i=i+1:
if i != 5 goto C
if i == 5 goto B

:C
echo Test :D

:B
pause>nul

Note: I don't know a lot of Batch and I'm not a pro, but I like to learn and I'm just doing this for future reference, and because I enjoy it. So, this code probably isn't good, but I want to know how I can accomplish this.
Reply

#2
To set a numerical value to a variable, you may use the `/a` switch:

> The /A switch specifies that the string to the right of the equal sign
> is a numerical expression that is evaluated.

(Type `SET /?` for all the help).

Second, check your `goto` flow - this never loops back to A.

Third, check the syntax of the `if` expression (`!=` doesn't exist in batch).
Reply

#3
This should work:

@echo off
set var1=0

:loop
set /a var1=%var1%+1

echo %var1%

if %var1% EQU 5 (
goto :end
) else (
goto :loop
)

:end
pause
Reply

#4
This is a way to simulate the while loop you are trying to accomplish. Only one `goto` is needed:

@echo off
set /a x=0
:while
if %x% lss 5 (
echo %x%
pause>nul
set /a x+=1
goto :while
)
echo Test :D
Reply

#5
@echo off
set a=0
:Count
set /a a=a+1
echo %a%
goto Count
Reply

#6
You can do that with a simple `FOR` command :


for /l %%x in (0,1,100) do (
echo %%x
)
You can replace `100` by the number you want
Reply

#7
try this:

<!-- begin snippet: js hide: false console: false babel: false -->

@if (@CodeSection == @Batch) @then

@echo off
:a
cls

color c
echo --------------
echo start:
echo --------------
set /p start=
cls

echo --------------
echo start: %start%
echo --------------

echo --------------
echo stop:
echo --------------
set /p stop=
cls

echo --------------
echo start: %start%
echo --------------

echo --------------
echo stop: %stop%
echo --------------
echo.
echo.

echo Start in:
timeout /t 2 /nobreak >nul

echo. 5
timeout /t 1 /nobreak >nul

echo. 4
timeout /t 1 /nobreak >nul

echo. 3
timeout /t 1 /nobreak >nul

echo. 2
timeout /t 1 /nobreak >nul

echo. 1
timeout /t 1 /nobreak >nul
cls

echo --------------
echo start: %start%
echo --------------

echo --------------
echo stop: %stop%
echo --------------

echo.
echo.
echo.

echo ============================================
set SendKeys=CScript //nologo //E:JScript "%~F0"
%SendKeys% ">----"
%SendKeys% "{enter}"
:while
echo %start%
%SendKeys% "%start%"
%SendKeys% "{enter}"
set /a start=start+1
timeout /t 1 /nobreak >nul
if %start% leq %stop% goto :while
goto :end

:end
echo ============================================
%SendKeys% ">----"
%SendKeys% "{enter}"

:c
echo count again? Y/N
set /p return=
if %return% == Y goto :a
if %return% == N goto :b
goto :c

:b
@end

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

<!-- end snippet -->

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through