switch

C#: Workaround for Illegal Switch Statement?

Possible Duplicate: Switch statement fallthrough in C#? The following code is illegal in C# because control cannot fall through from one case label to another. However, this behaviour is perfectly legal in C++. So, how would you go about coding the same behaviour in C#? enum TotalWords { One = 1, Two, Three, Four } ...

Ruby Convert If Statements to Case

Is it possible to use a case statement to replace these if statements? if (a%3 == 0) then puts "%3" elsif (a%4 == 0) then puts "%4" elsif (a%7 == 0 && a%13 == 0) then puts "%%" ...

Code before the first 'case' in a switch-statement

In C it's possible to write code before the first case label. Are there any cases for which it is useful to do this or is it just a 'dead block of code' ? E.g.: switch (...) { { int a = 0x2a; printf("%d\n", a); } case 0: ... } ...

Are there any disadvantages of using PHP compared to html?

I have a few pages out (not too many though) and I was just thinking that I might want to change all of the pages to php instead of html. I am planning on using php in the future, I am just not quite ready yet to make it my full-time language. I know anythign you can do with html pages, you can do with php pages, but I just wanted to kno...

Switch optimization for many cases guarantees equal access time for any case? ( C++ )

Hi, I've seen answers here for specific languages, about switches with more than 5 cases being optimized with jump tables to guarantee constant access time for any case. Is that so for C / C++? Is it in particular for gcc? for visual studio? If not, would sorting cases in order of occurrence frequency help? ...

using continue in a switch statement

I want to jump from the middle of a switch statement, to the loop statement in the following code: while (something = get_something()) { switch (something) { case A: case B: break; default: // get another something and try again continue; } // do something for a handled something d...

How to load specific flash while switching different lang in ASP.NET web application ?

Hi I've built a multilingual ASP.NET web app and no problem . I'm trying to put a flash header for this website so I've made couple flash in different language ( because they are different not just in language , they have tiny different because of different cultures ) . But my problem is i don't know how to load specific flash while ...

Using default in a switch statement when switching over an enum

What is your procedure when switching over an enum where every enumeration is covered by a case? Ideally you'd like the code to be future proof, how do you do that? Also, what if some idiot casts an arbitrary int to the enum type? Should this possibility even be considered? Or should we assume that such an egregious error would be cau...

Simplifying switch statement (Objective-C)

Y'hello.. Yep, it's me again, sorry. I am trying to .. um, see the code, you'll understand. If not, I'll explain later. // When row is selected - (void)pickerView:(UIPickerView *)pickerTimer didSelectRow:(NSInteger)row inComponent:(NSInteger)component { switch (row) { case 0: NSLog(@"It obviously worked.0"); ...

2 variable switch loop

Hi everyone, Is it possible to use switch statement over if else when condition is made of 2 variables. Thanks. added: foreach( DataRow row in workingTable.Rows ) { if( isKey && isValue ) workingDictionary.Add( row[ keyIdentifier ].ToString(), row[ valueIdentifier ] ); ...

PHP switch with GET request

I am building a simple admin area for my site and I want the URLs to look somewhat like this: http://mysite.com/admin/?home http://mysite.com/admin/?settings http://mysite.com/admin/?users But I am not sure how I would retrieve what page is being requested and then show the required page. I tried this in my switch: switch($_GET[]) { ...

PHP Switch Nav system - how can i set it up to use 2 GET variables

I use a the following PHP switch for my navigation menu: <?php include("header.php"); if (! isset($_GET['page'])) { include('./home.php'); } else { $page = $_GET['page']; switch($page) { case 'about': include('./about.php'); break; ...

How to call switch function from using PHP

I have a ajax.php file that contains the following sample code: switch($_REQUEST['request_name']) { case 'edit': echo "edit mode"; break; case 'delete': echo "delete mode"; break; default: die("Error: wrong request name ".$_REQUEST['request_name']); ...

0 in switch case?

Hello! Sorry for maybe dumb question, but i have HUGE problem with one case when i have some int variable with value of 0(zero). switch ($starost_vozila){ case (0): switch ($podaci['tip_motora']){ case ("motor1"): $eko_taksa = 485; ...

UISegmentControl switch views??

Hello all, I have a UISegmentControl in my app and im trying to make it switch views like the app store. Ive tried this code with no luck: - (IBAction)segmentSwitch:(id)sender { UISegmentedControl *segmentedControl = (UISegmentedControl *) sender; NSInteger selectedSegment = segmentedControl.selectedSegmentIndex; if (selectedSegm...

Javascript switch statement with wildcard?

If my javascript ajaxes away to my server and returns an ID of 49 in the plain text format of [49] is there a way in which i an do something like this... (i have tested and doesnt work) switch(data) { case '[*]': (..etc.) break; } Where the wildcard is the * and i want to make sure it is enclosed within two square pare...

Switching Views in iPhone SDK?

How come this won't switch views for me? When I click the button it does nothing... -(IBAction)howtoplayButtonClicked{ howToPlayViewController = [[HowToPlayViewController alloc] initWithNibName:@"HowToPlayViewController" bundle:nil]; [self.navigationController pushViewController:howToPlayViewController animated:YES]; [HowToP...

Re-use previous activities?

I have activities that are create and launched from menu options. However Ive noticed that this may mean that sometimes there are two or more copies of the same activity. So Im wondering if there's a way to see if another activity is already instantiated and then have the application switch to it or create a new one if its not instantiat...

How do you use a switch case statement to convert Letters into numbers

I am making a black jack game and I need to use a switch case statement to convert A to 11, and T, Q, J, and K to 10, however I am not sure how to do the code. Would someone mind helping me with this problem? So far I have: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplicati...

Hook in datatemplate view switch/change

Hello, I am switching my UserControls via DataTemplate. When I leave the UserControl/DataTemplate View I need to ask wether the user wants to save or not because else all data will be lost like graphical location points x,y of a user drag/dropped Rectangle on a canvas. How can I hook into the datatemplate change and bring up my own sav...