HomeJava & J2EE Page 2 - The JSP Files (part 3): Black Light And White Rabbits
Doing More With 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.
There's one caveat with the "while" loop. If the conditional expression evaluates as false the first time, the code within the curly braces will never be executed. If this is not what you want, take a look at the "do-while" loop, which comes in handy in situations where you need to execute a set of statements *at least* once.
Here's what it looks like:
do
{ do this! } while (condition)
For example, the following lines of code would generate no output whatsoever, since the conditional expression in the "while" loop would always evaluate as false.
<%
int bingo = 366;
while (bingo == 699) { out.println
("Bingo!"); break; }%>
However, the construction of the "do-while" loop is such that the statements within the loop are executed first, and the condition to be tested is checked after. Using a "do-while" loop implies that the code within the curly braces will be executed at least once - regardless of whether or not the conditional expression evaluates as true.
<%
int bingo = 366;
do
{
out.println ("Bingo!");
break;
} while (bingo == 699);
%>