• Post Reply Bookmark Topic Watch Topic
  • New Topic

why infinite loop

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given a scriplet as follows:

<%@ page language="java" %>

<%
int x=0;
while(x<=10)
{
%>
out.println(%=x++%);
<%
}
%>

The output of the above Jsp file is: the value of x never increments,the program goes into infinite loop. Why is this so?

Thanks.
Yan
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably because you try to increment x outside of JSP <% %> brackets.
 
Prakash Gorthy
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It must be something like this

<%@ page language="java" %>

<%
int x=0;
while(x<=10)
{
out.println(x++);
}
%>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It must be something like this


Not "must". He can also use scriplet expressions; he's just sort of mixed up his notation. Either use out.println inside the scriptlet, or use the correct scriplet expression notation of:



outside the scriptlet(s).
[ July 12, 2005: Message edited by: Bear Bibeault ]
 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, here is the way to do it (missing < >

<%@ page language="java" %>

<%
int x=0;
while(x<=10)
{
%>
out.println(<%=x++%> ;
<%
}
%>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, here is the way to do it


No, not really.

The out.println is meaningless outside of the scriplets.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!