Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Acessing local variable..ple help

 
Chuan Ren
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code, can you please help me to figure out how I could access the f_seat_status variable outside the if loop? Thank you.
<%
int l_session_seats_available =3;
if (l_session_seats_available > 0) {
String f_seat_status = "enrolled";
} else if (l_session_seats_available <= 0) {
String f_seat_status = "waiting list";
}
%>
<%=f_seat_status %> <--- How do I get the f_seat_status outside the IF loop??
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. The scope of the variable is visible only in the block you declared it. Why don't you declare it outside?
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
You can write the code in the following way

Just declare outside the scope.
hth
MB
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Despite the fact that this appears within a JSP, it's really a basic Java question, so I'm going to move this off to Java in General (beginner).
bear
[ October 21, 2003: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic