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 9247089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:38:45+00:00 2026-06-18T09:38:45+00:00

I would like to ask your help in a possibly simple situation (where the

  • 0

I would like to ask your help in a possibly simple situation (where the solution is yet unknown for me).

I am trying to provide a variable for the if command to make a bit more “dynamic” the code, but this fails for me with:
% was unexpected at this time.

Here is a simple example for that:

> for %i in (NEQ) do (if 1 %i 2 echo jo)
%i was unexpected at this time.

While the following works like charm:

>set oper=NEQ
>for %i in (NEQ) do (if 1 %oper% 2 echo works)
works

As I should stay in the for loop (and I get the actual operator from the for loop in the real code), I am really stuck how to solve it…

Tried to play with EnableDelayedExpansion as well, but !variable! instead of the operator is refused as well. Is there a way to submit the variable in a FOR loop for IF, without major modifications in the script?

  • 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-06-18T09:38:46+00:00Added an answer on June 18, 2026 at 9:38 am

    Is there a way to submit the variable in a FOR loop for IF?

    No!
    Because, the IF statement has it’s own parser and it expects some tokens already expanded at this parse phase.
    So it’s neither possible to expand the options nor the operator, nor NOT.
    But it’s allowed to expand the values with delayed or FOR-variables.

    setlocal EnableDelayedExpansion
    set myOperator=EQU
    IF 1 %myOperator% 1 echo Works
    IF 1 !myOperator! 1 echo FAILS
    for %%O in (EQU) do IF 1 %%O 1 echo Works
    

    The percent expansion works, as it is expanded before the IF parser gets the line.

    If you really need to use variable operators, then you need to use a function.

    for %%O in (EQU) do call :myFunc %%O
    exit /b
    
    :myFunc 
    IF ONE %1 ONE echo Works
    exit /b
    

    EDIT:
    And the special parser is also the cause, that it’s not possible to use here a CALL expansion for the IF statement.

    Like this idea

    set myOperator=EQU
    CALL IF 1 %%myOperator%% 1 echo Works
    

    This should expand to IF 1 EQU 1 echo Works, but the combination of CALL and IF fails always.

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

Sidebar

Related Questions

Hello everybody :D I would like to ask for your help on this problem.
I use c#, linq and EF4 I would like ask your help. My question:
I would like to ask for your help for constructing a single ORACLE SQL
Hello I would like to ask your help regarding javascript code, how do I
I am quite new about using Solr, but would like to ask your help.
i would like to ask for your help since I'm having difficulty resolving this
I would like to ask your help, I'm kind of lost. I am upgrading
I would like to ask your guidance on how to authenticate using email add/
I'd like to ask for your help concerning Android's built in Camera Interface When
I would like to ask your opinions regarding the way I handle MultiTenancy. Im

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.