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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    82 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    43 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    56 views
    0 likes
    Last Post CarlTrading  
    Working...
    X