This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "for loop" Watch "for loop" New topic
Author

for loop

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
for(int i =0;i<3;i++)
out.println("hello");
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
Hi,
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++)
jspwriter.print("\r\n");
jspwriter.print(StringUtils.valueOf("hello"));
jspwriter.print("\r\n<BR>\r\n");
for(int j = 7; j > 3; j--)
jspwriter.print("\r\n");
jspwriter.print(StringUtils.valueOf("hello"));
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.

Mahesh
Anonymous
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: http://aspose.com/file-tools
 
subject: for loop
 
Similar Threads
Label (Continue)
Label???
XML VIEW OF JSP PAGE:
How to write jsp with xml syntax
while-loop