Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:35:34+00:00 2026-05-27T04:35:34+00:00

I am having problems getting the desired result in cmd batch file. I need

  • 0

I am having problems getting the desired result in cmd batch file. I need to print the result in the below mentioned format

@echo off
setlocal enabledelayedexpansion
for %%i in (8 7 6 5 4 3 2) do (

echo %%i
if %%i EQU 8 goto lvl8
if %%i EQU 3 goto lvl35
if %%i EQU 2 (goto lvl3) else goto lvls

:lvl8
set str1=8
set str2=16

:lvl35
set str1=3.5
set str2=4

:lvl3
set str1=3
set str2=3.5

:lvls
set str1=%%i

set /A str2=%%i+1

echo %%i
rem echo.!str!
echo.!str1!
echo.!str2!
)
endlocal

Expected outputs

8
8
16
7
7
8
6
6
7
5
5
6
4
4
5
3
3.5
4
2
3
3.5

Right now am getting the following:

8
Missing operand
%i

%i
3.5

EDIT: updated the above question as per Joey’s solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:35:35+00:00Added an answer on May 27, 2026 at 4:35 am

    %i% has no value. Were you intending to use %%i?

    To clarify, what cmd sees here:

    if  EQU 8 goto lvl8
    if  EQU 3 goto lvl35
    if  EQU 2 (goto lvl3) else goto lvls
    

    which clearly is a syntax error.


    Ok, after your edit, there are a few problems, still. If you use goto you apparently leave the for loop. Thus, after a goto %%i doesn’t have a value, either and the loop only runs once.

    Then there is the way you use the gotos; a goto is a jump to a specific line in code. Program flow continues normally after that and thus if you jump to lvl8 you end up running all subsequent lines, too, even those after :lvl35 and :lvl3 or :lvls. After each section you jump to you’d have to include an explicit jump to the end of the loop to skip the unwanted lines. But that’s semi-beside the point, as you cannot use goto within the for loop, as mentioned above.

    So the first thing you should do is get rid of goto and instead use structured programming. if can accept a block, too. Then you output %%i once too often, which can easily be corrected, too.

    It now looks like this here:

    @echo off
    setlocal enabledelayedexpansion
    for %%i in (8 7 6 5 4 3 2) do (
        echo %%i
    
        if %%i EQU 8 (
            set str1=8
            set str2=16
        ) else if %%i EQU 3 (
            set str1=3.5
            set str2=4
        ) else if %%i EQU 2 (
            set str1=3
            set str2=3.5
        ) else (
            set str1=%%i
            set /A str2=%%i+1
        )
    
        rem echo %%i
        rem echo.!str!
        echo.!str1!
        echo.!str2!
    )
    endlocal
    

    Note that each if also has an else to avoid running the last else for all numbers except 2. The output is now correct. Code can be found in my SVN repository, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems getting the desired behavior out of these few classes and
I am having problems getting text within a table to appear centered in IE.
I am having problems getting my form to Post to my Save method in
I am having problems getting JBoss to inject an environment variable value into a
I am having problems getting the 'ByAccount' aggregation to work in SQL Server Analysis
I've been having problems getting jqmodal modal dialogs to display on links added dynamically
I am having problems getting at a click event of a button and am
I am having problems getting my Permalinks changed with my Wordpress instance. I have
I am having problems getting validation to work for a form built using Zend_Form.
I'm having problems getting my game engine to run on my brother's machine, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.