Forums Register Login

Acessing local variable..ple help

+Pie Number of slices to send: Send
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??
+Pie Number of slices to send: Send
You can't. The scope of the variable is visible only in the block you declared it. Why don't you declare it outside?
+Pie Number of slices to send: Send
Hi..
You can write the code in the following way

Just declare outside the scope.
hth
MB
+Pie Number of slices to send: Send
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 ]
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 548 times.
Similar Threads
variable declaration and object creation in side loop
missing return statement error message when compiling class
Variable Scope
doubt regarding garbage collection
Limit character read using Reader?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:09:42.