Home arrow Java & J2EE arrow Page 4 - The JSP Files (part 3): Black Light And White Rabbits

The Sound Of Breaking Loops - Java

This week, learn all about the different types of loops supportedby JSP, and also expand your knowledge of the various String objectmethods. Finally, take a quick tour of the JSP Response object inpreparation for learning how JSP handles form data.

TABLE OF CONTENTS:
  1. The JSP Files (part 3): Black Light And White Rabbits
  2. Doing More With Loops
  3. For-gone Conclusion
  4. The Sound Of Breaking Loops
  5. Paying The Piper
  6. You Say Seven, I Say 7
  7. A Positive Response
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 2
March 01, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
When dealing with loops, there are two important keywords you should be aware of: "break" and "continue".

The "break" keyword is used to exit a loop when it encounters an unexpected situation. A good example of this is the dreaded "division by zero" error - when dividing one number by another one (which keeps decreasing), it is advisable to check the divisor and use the "break" statement to exit the loop as soon as it becomes equal to zero.

As you've already seen, the "continue" keyword is used to skip a particular iteration of the loop and move to the next iteration immediately - it's demonstrated in the following example:



<% int x; for (x=1; x<=10; x++) { if (x == 7) { continue; } else { out.println(x + ""); } } %>


In this case, JSP will print a string of numbers from 1 to 10 - however, when it hits 7, the "continue" statement will cause it to skip that particular iteration and go back to the top of the loop. So your string of numbers will not include 7 - try it and see for yourself.

 
 
>>> More Java & J2EE Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: