This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Acessing local variable..ple help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 60789
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: Acessing local variable..ple help
 
Similar Threads
doubt regarding garbage collection
variable declaration and object creation in side loop
Variable Scope
Limit character read using Reader?
missing return statement error message when compiling class