switch-statement

Bitwise flags and Switch statement?

I have the following code (example), and I'm really not comfortable with so many 'if' checks: public enum Flags { p1 = 0x01, // 0001 p2 = 0x02, // 0010 p3 = 0x04, // 0100 p4 = 0x08 // 1000 }; public static void MyMethod (Flags flag) { if ((flag & Flags.p1) == Flags.p1) DoSomething(); if ((...

If error then switch vs. switch with "good" case

Hello all. I'm not very familiar with machine code, but I think this is a pretty simple question. If I want to do error handling via an integer returned from a function (as opposed to the function throwing an exception), is it better practice—from a machine code standpoint—to: Check the integer in a conditional statement for a "bad"...

C# Switch-case string starting with....

Is there any way to make a case condition in a switch statement where you say if a string begins with something? ex Switch (mystring) { case("abc")://String begins with abc (abcd or abc1 or abcz or abc.. or abc will fall in this condition). //Do Something break; default: break; } UPDATE Other strings can be di...

not working IE8 if option value selected switch css

i know there is probably a better way of doing this, i have tried many ways. i would normally do the .hide() or .show() but the css display switch has been working better on FF, not on IE. anyway here is my code $(".VariationSelect option[value='21']").click(function () { $("#21").css("display", "block"); }); $(".VariationSelect opt...

problem with if/else and switch statements in android

the following code is to handle ACTION_DOWN and ACTION_UP events for a button named clash. the idea is that once if/else determines that the onTouch event was caused by clash and the switch statement then determines what to do based on the action. i don't know if the problem is that the switch statements are not returning true and that...

Evaluating every conditional statement on an if... else if... block

Does Objective-C evaluate every statement on an if... else if... block or does it evaluate each as it comes to them and then skip the remaining evaluations if a true condition has been found? This is more of a pragmatic question related to performance than anything else. And yes I do know that the content of the if block itself isn't e...

Since Python doesn't have a switch statement, what should I use?

Possible Duplicate: Replacements for switch statement in python? I'm making a little console based application in Python and I wanted to use a Switch statement to handle the users choice of a menu selection. What do you vets suggest I use. Thanks! ...

Switch on enum in JNI?

Given: enum Foo { FIRST, SECOND } What is the JNI equivalent for the following code? Foo foo = ...; int value; switch (foo) { case FIRST: value = 1; break; case SECOND: value = 2; break; } I know I can use foo.equals(Foo.FIRST) from JNI, but I'd like to get the same performance as switch(enum). Any ideas? ...

Switch Case Assembly Language

I am looking at the assembly language code of a switch statement. I understand how the code works and what the cases are. My question is how do I decide on the case names? Below is the assembly language code, which will be followed with my interpretation of it. I basically just need to use the jump table and fill in the case names. ...

c++ fatal error C1061 with large switch, metaprogramming

that's the code: static inline void shrinkData(const vector<Data> &data, unsigned short shrinkType){ #define CASE_N(N) \ case(N): \ ptr = MemoryManager::requestMemory(n*sizeof(ShrinkData<N>)); \ for(int i=0; i<n; i++){ \ new(ptr) ShrinkData<N>(data[i]); \ ptr+=sizeof(ShrinkData<N>); \ ...

regexp in switch statement.

Are regex's allowed in PHP switch/case statements and how to use them ? ...

Count words, java

Hi, I want to count words. I use the methods hasNextChar and getChar. The sentence may contain all kind of chars. Here's my code: boolean isWord = false; while(hasNextChar()){ char current = getChar(); switch(current){ case ' ' : case '.' : case ',' : case '-' : ...

problem with Switch Case

I am creating a UIView dynamically and adding a scrollview in it. What I want is to create mutiple scrollviews and add them by using SWITCH Case. I am passing an integer value called num on IBAction of a button on UIView. and calling the function to create a scrollview. -(IBAction) button1pressed{ num = 1; NSLog(@"value %d",num...