aspose file tools
The moose likes Beginning Java and the fly likes Acessing local variable..ple help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Acessing local variable..ple help" Watch "Acessing local variable..ple help" New topic
Author

Acessing local variable..ple help

Chuan Ren
Ranch Hand

Joined: Aug 04, 2003
Posts: 42
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

Joined: Nov 27, 2001
Posts: 1561
You can't. The scope of the variable is visible only in the block you declared it. Why don't you declare it outside?


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Hi..
You can write the code in the following way

Just declare outside the scope.
hth
MB


Malhar Barai
SOA & Java Book
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

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 ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Acessing local variable..ple help
 
Similar Threads
Variable Scope
missing return statement error message when compiling class
variable declaration and object creation in side loop
doubt regarding garbage collection
Limit character read using Reader?