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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    31 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    12 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    18 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X