Java & J2EE The JSP Files (part 3): Black Light And White Rabbits |
Last time out, you learned a little bit about the various conditional statements and operators available in JSP. This week, we'll expand on those basics by teaching you a little bit about the different types of loops available in JSP, discuss a few more String object methods, and take a quick tour of the new Response object. First up, loops. As you may already know, a "loop" is a programming construct that allows you to execute a set of statements over and over again, until a pre-defined condition is met. The most basic loop available in JSP is the "while" loop, and it looks like this: Or, to make the concept clearer, The "condition" here is a standard conditional expression, which evaluates to either true or false. So, were we to write the above example in JSP, it would look like this: Here's an example: Here, the variable "countdown" is initialized to 30, and a "while" loop is used to decrement the value of the variable until it reaches 0. Once the value of the variable is 0, the conditional expression evaluates as false, and the lines following the loop are executed. Here's the output:
blog comments powered by Disqus |