Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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..
 
All of the following truths are shameless lies. But what about this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic