File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "for loop" Watch "for loop" New topic

for loop

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
for(int i =0;i<3;i++)
IS this same as
<%for(int i =0;i<3;i++)%>
<%= "hello"%>
<%for(int i=7;i>3;i--)%>
<%= "hello" %>
prints hello once
<%for(int i=7;i>3;i--)%>
What i<br>
prints what i 4 times why is this so?
[ April 24, 2002: Message edited by: shan java ]
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
If u have a look at the compiled servlet class file of the jsp, it looks something like this
for(int i = 0; i < 3; i++)
for(int j = 7; j > 3; j--)
jspwriter.print("\r\nprints hello once\r\n<BR>\r\n");
for(int k = 7; k > 3; k--)
jspwriter.print("\r\nWhat i<br>\r\n\r\n\r\n\r\n\r\n</body>\r\n</html>");
What this specifies is in the first for looop, if you want hello to be printed more times, u'll have to change it to
<%for(int i =0;i<3;i++){%>
<%= "hello"%>
<% } %>
Hope Ur problem is solved.

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanx Mahesh for taking pains but still is not clear.
I know how to make "hello" rint 4 times but
need to know the difference in output when I give a out.print statement or just a expression or a template text.
Is the answer due to "\r\n" ..what exactly does this mean..
I agree. Here's the link:
subject: for loop
It's not a secret anymore!