Skip to main content
Post a question

Notifications

Community site session details

Community site session details

Session Id : WonIw0WB+tlAEahQ0omyE4
Finance | Project Operations, Human Resources, ...
Answered

how to use for loop in between do while loop in x++

Like (0) ShareShare
ReportReport
Posted on 28 Feb 2020 08:47:05 by

Hi,

Can use for loop in between do while loop in x++,

I can try to use but syntax error occur. anyone give idea or suggestion about that.

Thanks in advance. 

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on 03 Mar 2020 at 07:11:03
    RE: how to use for loop in between do while loop in x++

    This error has nothing to do with having two loops. In AX2012 x++ you can't declare variables in the middle of methods, not even in the "for" statement. On the other hand, in D365 you can declare variables anywhere in the method, and Blue Wang's example is from D365

    So you have to declare int k in the beginning of your method.

    However I think you still didn't share your original code with us. So we don't know what might have been wrong with it. In your recent message you simply tried Blue Wang's example code. 

  • Blue Wang Profile Picture
    on 03 Mar 2020 at 06:02:15
    RE: how to use for loop in between do while loop in x++

    HI Ashokkumar ,

    Have you tried to recompile job?

  • Community Member Profile Picture
    on 03 Mar 2020 at 05:19:46
    RE: how to use for loop in between do while loop in x++

    Hi Blue Wang, thanks for your response

    I am also using same like this but showing error.forloop.PNG

  • Blue Wang Profile Picture
    on 02 Mar 2020 at 07:52:03
    RE: how to use for loop in between do while loop in x++

    Hi Ashokkumar,

    For what purpose do you need to design code like this?

    But I simply tried without prompting syntax problems, what about your code, please share with us.

    But as Nikolaos said, if you use nested loops, it will definitely affect performance.

    6864.PNG

  • nmaenpaa Profile Picture
    101,158 Moderator on 28 Feb 2020 at 09:15:38
    RE: how to use for loop in between do while loop in x++

    Also, normally you should try to avoid nested loops since they often lead to performance issues. Perhaps we can find together a better way to solve your requirement. If you share your functional requirement with us.

  • nmaenpaa Profile Picture
    101,158 Moderator on 28 Feb 2020 at 09:14:46
    RE: how to use for loop in between do while loop in x++

    Could you explain a bit more what you are trying to do. And also please show your code that gives you the error. Otherwise we can't know what might be wrong with it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,342 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans
Loading complete