Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Regarding Switch/Case argument
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Shiro786




PostPosted: Tue May 06, 2008 12:37 am   Post subject: Regarding Switch/Case argument

Hey everyone, Shiro again.

I was wondering if it was possible to output the contents of a switch/case argument from inside a for loop, outside of a for loop.








Thanks in advance, Shiro.
Sponsor
Sponsor
Sponsor
sponsor
Zampano




PostPosted: Tue May 06, 2008 12:57 am   Post subject: Re: Regarding Switch/Case argument

Quote:
from inside a for loop, outside of a for loop

Make up your mind!
Dan




PostPosted: Tue May 06, 2008 1:07 am   Post subject: RE:Regarding Switch/Case argument

The is no reason why you can not output in a for loop just as well as outside of it and the same goses for switch staments.

So yes you can output somthing in a switch stament in a for loop.

If that is not what you ment please add more details to your post and posibley some of your code.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Aziz




PostPosted: Tue May 06, 2008 12:46 pm   Post subject: RE:Regarding Switch/Case argument

Sample code would help. Yes, you can nest if's, for's, while's, and switches (and nest them inside of cases).
btiffin




PostPosted: Tue May 06, 2008 1:26 pm   Post subject: Re: Regarding Switch/Case argument

In Java, scope and extent are fairly common sensical. You kind of have to work hard to trick scoping rules to be "non obvious".

So, a case structure with a local switch argument variable name may not be accessible from an outside for loop. Inner for, no problem. Scope is hierarchical unless told (tricked) otherwise. As Java allows declarations just about anywhere, if you need access to an inner scoped local, just declare it before hand (umm, of course it will no longer be "local" to the switch).
code:
switch (int lvar = somearg) {
...
}
lvar will be local and outside constructs will not have scope access.
code:

int switchvar = somearg;
...
switch (switchvar) {
...
}
will give access to switchvar from within whatever scope you happen to put it in (usually but not always nested by brace).

I'll leave the private public and other modifiers as an exercise to the reader with hints at http://java.sun.com/docs/books/tutorial/java/nutsandbolts/variables.html

Cheers
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: