Click here to watch in Youtube :
https://www.youtube.com/watch?v=arKelkWutMk&list=UUhwKlOVR041tngjerWxVccw
BreakDemo.java
Output
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); } }
element inside for :Apple element inside for :Ball foundIt :true
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:
No comments:
Post a Comment