switch-case

replace a bunch of show/hide with switch/case in javascript

Page has menu items that would replace a 'div id=foo_(current menu item)' with 'div id=foo_(selected menu item)' in 'div class=foo' Here's what I've got, and try to keep your breakfast down... $('#t1').click(function() { $('#attorney').show(); $('#insurance,#financial,#estate,#trust,#death').hide(); }); $('...

Is there a more efficient way to run enum values through a switch-case statement in C# than this?

I was wondering if there was a more efficient (efficient as in simpler/cleaner code) way of making a case statement like the one below... I have a dictionary. Its key type is an Enum and its value type is a bool. If the boolean is true, I want to change the color of a label on a form. The variable names were changed for the example. D...

Switch-Case for strings in Javascript not working as expected

So I have this problem with strings and switch-case, and I'll try to keep it as simple as possible. Here event.keyCode has the value "65", and is the result of a keydown event of 'a' (using JQuery). if (event.keyCode == "65") { alert("hmmmm"); } That works, but: switch (event.keyCode) { case '65': alert("Yay!"); b...

dynamical binding or switch/case?

A scene like this: I've different of objects do the similar operation as respective func() implements. There're 2 kinds of solution for func_manager() to call func() according to different objects Solution 1: Use virtual function character specified in c++. func_manager works differently accroding to different object point pass in. ...

C# Switch-case Loop for Datagridview cells

Hi, I am working on a form with datagridview and webbrowser controls. I have three columns as URL, username and password in datagridview. What I want to do is to automate the login for some websites that I use frequently. For that reason I am not sure if this is the right approach but I created the below code. The problem is with the ar...

Switch case in jquery

Am I writing the correct switch case? var cnt = $("#div1 p").length; alert(cnt); switch (cnt) { case (cnt >= 10 && cnt <= 20): alert('10'); break; case (cnt >= 21 && cnt <= 30): alert('21'); ...

Why do switch statements continue after case

After evaluating a case in a switch statement in Java (and I am sure other languages) the following case's are also evaluated unless a control statement like break, or return is used. I understand this is probably an implementation detail, but what is/are the reasons for having this functionality happen? Thanks! ...

Does the order of case in Switch statement can vary the performance?

Let say I have a switch statement as below switch(alphabet) { case "f": //do something break; case "c": //do something break; case "a": //do something break; case "e": //do something break; } Now suppose I know that the frequency of having Alphabet e...

Swapping switch-case in extra fle/data structure (Java)

Hi guys, it may be a nooby question, but I've never needed it before: I have several strings and I want to compare them to given ones... At first glance it would lead to a switch/case construction in what every available entry is checked. Is there a more elegant way to swap those strings as key/value datas? greets, poeschlorn ...

Access control of page in php

Hello, I want to control the access in php website. I have a solution right now with switch case. <?php $obj = $_GET['obj']; switch ($obj) { case a: include ('a.php'); break; default: include ('f.php'); } ?> But when i have so many pages, it becomes difficult to manage th...

If-elseif-else Logic Question

I have a set of three values, call them x, y, and z. If value A happens to match only one in the set x, y, and z, then that means we have a proper match and we stop searching for a match, even if it is at y. It can match any one in that set. These values x, y, and z are non-constant so I cannot use a switch-case statement. How do I do ...

While within a switch block

Hi, I've seen the following code, taken from the libb64 project. I'm trying to understand what is the purpose of the while loop within the switch block - switch (state_in->step) { while (1) { case step_a: do { if (codechar == code_in+length_in) { st...

Is there a switch case in Javafx 1.2?

A simple yes or no would suffice :) Thanks! ...

Why are different case condition bodies not in different scope?

Why are different case bodies not automatically in their own scope? For example, if I were to do this: switch(condition) { case CONDITION_ONE: int account = 27373; case CONDITION_TWO: // account var not needed here case CONDITION_THREE: // account var not needed here case CONDITION_FOUR: int account = 90384; } ...

Case-insensitive switch-case

OK, so let's say I have this: $(function() { $('#good_evening').keyup(function () { switch($(this).val()) { case 'Test': // DO STUFF HERE break; } }); }); ... this would only run if you typed "Test" and not "test" or "TEST". How do I make it case-insensitive for JavaScript functions? ...

Switch-Case: declaration-with-initialization & declaration-and-then-assignment

In the switch-case statements declaration-with-initialization is invalid but declaration-and-then-assignment is allowed. As shown in the following code snippet. What is difference between these two type of initializations from the compiler side? And why is the first type of initialization invalid and second type a valid one. switch(va...

Wierd Switch case error (iPhone sdk) UITableView

Hi, I am getting a weird compilation error - I dont know if there is a "ghost in the machine" or what? Below if the code snippet where I am getting this error - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell ...