Friday 20 November 2015

Java Tutorial : Java Break statement


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=arKelkWutMk&list=UUhwKlOVR041tngjerWxVccw

BreakDemo.java
class BreakDemo
{
    public static void main(String[] args)
    {

        String[] strArray = { "Apple", "Ball", "Cat", "Dog", "Egg" };

        String searchFor = "Cat";
        boolean foundIt = false;

        /*
         * This program searches for the String value 'Cat' in an array. The
         * break statement terminates the for loop when that value is found.
         * Control flow then transfers to the statement after the for loop.
         */
        for (String element : strArray)
        {

            if (searchFor.equalsIgnoreCase(element))
            {
                foundIt = true;
                break;
            }
            System.out.println("element inside for :" + element);
        }

        System.out.println("foundIt :" + foundIt);
    }
}
Output
element inside for :Apple
element inside for :Ball
foundIt :true
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ControlFlowDemoBreakApp.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ControlFlowDemoBreakApp

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/9f2088c41ff235b2716289e24cabde9d7d07fb91/BasicJava/ControlFlowDemoBreakApp/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment