Home Jsp Use while loop in jsp code
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Use while loop in jsp code

Advertisement
While loop is a control flow statement that works repeatedly based on a given boolean condition, loop will continuously execute the statements given in the body as long as a given condition is true.

Use while loop in jsp code

     

While loop is a control flow statement that works repeatedly based on a given boolean condition, loop will continuously execute the statements given in the body as long as a given condition is true.

 

 

 

 

While loop checks the condition before the body execution so this is also called pre test loop. This is the main difference between while and do while loop, do while loop first execute the loop body then checks the boolean condition.

Before run this jsp code create a new directory named "user" in the tomcat-6.0.16/webapps and paste WEB-INF directory in same.

while_statement.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
  <HEAD>
    <TITLE>Using the while Loop in jsp</TITLE>
  </HEAD>
  <BODY>
    <H1>Using the while Loop</H1>
    <%  
	out.println("Loop will run 5 times.<br>");
        int i = 1;
	// while loop that runs five times
        while (i<6) {
            out.println("we are in loop value is : "+i+"<br>");
	    i++;
        }
        out.println("Now we are out of while loop.");
    %>
  </BODY>
</HTML>

Rum tomcat server by clicking on startup.bat file in bin directory ob tomcat. Save this code as a .jsp file named "while_statement.jsp" in the directory Tomcat-6.0.16/webapps/user/ and you can run this jsp page with following url in address bar of the browser http://localhost:8080/user/while_statement.jsp 

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 17, 2008

Related Tutorials

Ask Questions?    Discuss: Use while loop in jsp code   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
mutyaaguila
March 4, 2012
java loop

I am a beginner using java, can u give me an example of while loop using the messageinput dialog.tnx.
DMCA.com