Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Breaking the correct loop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Breaking the correct loop

    Hi
    I want the "break;" inside "if-statement E" in the code below to break "Loop A". Will it still do this even though the "break;" is "embedded" inside a bunch of other "if"-statements and "{}"-brackets?

    Thank you for any help!




    Code:
    for(int i = 1; i < scanbarsback; i++)                      // Loop A
    {
    
        if(BlaBla)
        {
            BlaBla
        }
    
        if( BlaBla)
        {
    
            for(int ia = 1; ia < VarC; ia++)                  //Loop B
            {
    
                if(BlaBla)
                {
                    BlaBla
                }
    
            }
    
            if (BlaBla)                                      // if-statement E
            {    
                BlaBla
                break;                                         // break;
            }
    
        }
    }

    #2
    Welcome to the forums Carpediem2020!

    Yes, if you call break within a loop, you will break out of that loop. You can use if statements in the loop to control when the break statement is reached.

    Loops are general C# concepts. We do not provide programming education services in the support department, so we would recommend referencing educational materials external to NinjaTrader to better learn these concepts. Below are some publicly available resources on looping in C#.

    The break statement in C# has following two usage &#8722; If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.


    C# break statement with examples. In c# break statement is used to terminate or stops the execution of loops or switch statement.


    We look forward to assisting.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    44 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    56 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    35 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    95 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    57 views
    0 likes
    Last Post PaulMohn  
    Working...
    X