• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

for loop

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Men call me Jim. Women look past me to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic