question archive Java: Build a simple JSP
Subject:Computer SciencePrice:2.86 Bought8
Java: Build a simple JSP. Call it "Loops.jsp". The JSP should simply print out 'GO BRAVES" 10 times. Use a loop to accomplish this.
<%! int counter; %> <html> <head> <title>FOR LOOP</title> </head> <body> <%for ( counter = 1; counter <= 10; counter++){ %> <p>GO BRAVES</p> <%}%> </body> </html>
Step-by-step explanation
In this, to initialize the for loop, we will first declare the counter variable as integer:
<%! int counter; %>
After this, we will go inside the body tag and then start a for loop as:
<%for ( counter = 1; counter <= 10; counter++){ %>
As you can see, here we will the initialize the counter to 1, and then in the condition segment it will run till the value is 10, and then also increasing by 1 every time. Inside the loop, we will write the "GO BRAVES", and then end the for loop using <%}%>.
See the output:
Please see the attached file for the complete solution