Documentations - SRON
  • SRON's Official Documentation
  • Installation
  • Syntax of SRON
  • Executing a SRON code
  • Keywords in SRON
  • Comments in SRON
  • Datatypes in SRON
  • Variables in SRON
  • Memory Ownership Model
  • Operators in SRON
  • Math block
  • if elif else in SRON
  • Loops in SRON
    • For Loop
    • While Loop
    • Foreach Loop
  • Break & Continue
  • Functions in SRON
    • Print functions
    • User Input Functions
    • Type Conversion functions
    • Type Checking functions
    • Math functions
    • Char Functions
    • String Functions
    • List Functions
    • Miscellaneous functions
  • Return in SRON
  • Command Line Arguments
  • Free
  • Rotate
  • Console
  • Sample codes
  • Coding Convention
  • Frequently Asked Questions
  • Credits
  • Contact
  • Donate
Powered by GitBook
On this page

Break & Continue

There are many scenarios in programming when you have to exit or restart a loop based upon a certain condition or scenario.

SRON provides 'break' and 'continue' keyword to control and manipulate the control flow of loops. Both of these keywords can only be used inside the scope of 'for', 'foreach' or 'while' attribute.

'break' keyword is used to shift the control flow of program outside the scope of loop. Let's take a look on usage of 'break' keyword. Below is a sample code:

{
    name : MAIN
    for : {
        range : (Int i = 1, 7)
        if : {
            condition : ~{ i == 5 }~
            println("Breaking the loop")
            break
        }
        println(i)
    }
    println("Outside the Loop!")
}

OUTPUT :

1 2 3 4 Breaking the loop Outside the Loop!


Now, let's see how 'continue' keyword. It is used to shift the control flow of program to the starting of the loop. See the below sample code for it:

{
    name : MAIN
    Int i = 10
    while : {
        condition : ~{ i < 20 }~
        if : {
            condition : ~{ i % 5 == 0 }~
            i += 1
            println("continuing loop")
            continue
        }
        i += 1
        println(i)
    }
    println("Outside the Loop!")
}

OUTPUT :

continuing loop 11 12 13 14 continuing loop 16 17 18 19 Outside the Loop!


PreviousForeach LoopNextFunctions in SRON

Last updated 6 months ago