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#.



    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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    661 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    375 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    110 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    580 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X