How to use 'continue' keyword in jsp page ?

This is detailed java code that shows how to use 'continue' keyword in jsp page.

How to use 'continue' keyword in jsp page ?

How to use 'continue' keyword in jsp page ?

     

This is detailed java code that shows how to use 'continue' keyword in jsp page. The continue statement skips the remaining statements in the body of the loop for the current iteration, and continues with the next iteration of the  same loop. In this example, we have developed use_continue_statement.jsp page which shows the use of 'continue' keyword in JSP. This page asks the user to enter some value and loop in the JSP code shows the square of the number and for the next 4 numbers also.

Restriction with 'continue' statement : It can only be used within the body of a while, do, or for statement.

use_continue_statement.jsp

<HTML>
<HEAD>
<TITLE>use of 'continue' statement through jsp</TITLE>
</HEAD>
<BODY bgcolor="#6E6E6E">
<FORM NAME="form1" ACTION="use_continue_statement.jsp" METHOD="get">           
<table bgcolor="#D8D8D8">
<font color="#F8E0F7">You can calculate square of given number.</font>
<tr>
<td> Enter number </td>
<td><input type="text" name="num"></td>
</tr>
<tr align="center">
<td></td>
<td><INPUT TYPE="submit" VALUE="square"></td>
</table><br>
<table bgcolor="#F6E3CE" border="1" width="23%">
  <%
   /* check that value in text box is null or text box is empty */
   if (request.getParameter("num") != null && request.getParameter("num") != "") {
    int count = 0;
    // change the string value from textbox to a long type
    long num = Long.parseLong(request.getParameter("num"));
    %>
     <font color="#F8E0F7">You can see here a list of squared number</font>
      <%
       while (true) {
      %>
       <tr align="center">
         <td><Font>Square of  <%= num + count%></font></td>
           <td><%= ((num + count) * (num + count))%></td>
             </tr>
             <%
           count++;
	   if(count<5)
	   /* use continue statement to transfer control to the start of this loop */
            continue;
		else
		           /* use break statement to transfer control out of this loop */
              break ;
                   }
               }%>
            </table>
        </FORM>
    </body> 
</html>

Save this code as a .jsp file named "use_continue_statement.jsp" in your application directory in tomcat server and run this jsp page with the following url in address bar of the browser  http://localhost:8080/user/use_continue_statement.jsp

When user enter integer value in appropriate text box and click square button.
For this example, suppose user enters value 25.

 Download source code