FAQ Database Discussion Community


Swift custom UITableViewController: switch statement case label section enum

ios,uitableview,swift,enums,switch-statement
To make my code more readable & maintainable, what's the best way to use labels instead of hardcoded Ints for case labels in a switch statement with a control expression of type Int? E.g., inside my SettingsTableViewController, I tried enum Section : Int { case Phone case LogOut case DeleteAccount...

if, else if, else statements: Within the blocks of code

java,loops,if-statement,netbeans,switch-statement
I am a beginner programmer, and am currently banging my head against the wall over this assignment. I have to create a program that 'simulates' the use of a car, so it goes: drive, park, and fill up. The first thing it does is ask for how many litres of...

Inequalities inside a switch statement [duplicate]

javascript,switch-statement
This question already has an answer here: Javascript conditional switch statement 5 answers I just started learning about the switch command in JavaScript, and was wondering if the cases could be constructed so as to include inequalities (<, >, <= and >=), instead of equality (==). Also, can one...

SQL subquery (stockin quantity runtime by sum up the stock in and stock out group by store and than subtract from stockin to stock out)

sql,switch-statement,subquery,inner-join,correlated-subquery
I have 2 tables stockin and stockout i want to calculate stockin quantity runtime by sum up the stock in and stock out group by store and than subtract from stockin to stock out .. My query is working well but when it doesnt found any record in stock out...

How to extend Activity in main class that extends “Fragment”?

java,android,android-fragments,switch-statement,navigation-drawer
I have an Android project and I use Navigation Drawer in it, and in the MainActivity, I have a switch-case, with options and your respective positions for to open when the user clicks. But, in a class called TelaQUEMSOMOS, the parameters that are there: public class TelaQUEMSOMOS extends Fragment {...

c++ Declaring a variable inside a switch statement

c++,scope,switch-statement,variable-declaration
I have a switch statement in my C++ code, and want to declare and use a variable inside a case of that statement. The variable will only be used inside the scope of that particular case. switch(mode) { case abc: ... struct commonData; commonData = manager->getDataByIndex(this->Data.particularData); int someInt = 1;...

Switch case gets executed twice

objective-c,loops,switch-statement
I have the following piece of code : (it's long) //declarations (in the header) : NSDictionary* batteryRawDict; @property (strong, atomic, readonly) NSDictionary* batteryReport; //this dictionary is, obviously, @synthesize'd -(BOOL) refreshGroup:(PFSystemKitGroup)group { kern_return_t result; switch (group) { case PFSKGroupGraphics: { val4Key("graphicReport", [self listGraphics]); //break; } case PFSKGroupBattery: { //to get more...

Is there a way of checking more than one condition in Swift switch?

ios,swift,switch-statement
In swift, I need to make a switch like this: switch char { case "+": statement 1; statement 3 case "-": statement 2; statement 3 default: statement 3 } However, I don't want to copy the statement 3, because it is actually quite long, so I'm looking for an alternative...

Swift: Animating UIButton after auto-formatting UITextField

ios,swift,uibutton,switch-statement,uitextfield
I have a UITextField that only takes numbers. It's a phone number field. Once there are 10 characters in the field (area code + number), I convert the textField.text string to an NSMutableString to format it to a phone number. Now, once the format takes place, I need to animate...

Best practice to create two-level deep selection menu in Java console

java,menu,switch-statement
I'm about to create an application that runs off the java console as opposed to the GUI, and I had a question about the best way to approach displaying menus with another level of a submenu. I've quickly typed up the below code to sort of give you an idea...

why the following code gives the first mobile no. irrespective of name

c,string,switch-statement,comparison
Please explain why the following code gives the first mobile no. irrespective of entered name: #include<stdio.h> #include<conio.h> int mobileno(char[]); int main(){ char input[20]; gets(input); printf("%s",input); int x; x = mobileno(input); printf("%d",x); switch(x){ case 0:printf("7255222319");break; case 1:printf("9404521113");break; case 2:printf("9326513553");break; case 3:printf("9845621611");break; case 4:printf("4556312390");break; case 5:printf("9245178190");break; case 6:printf("9214188214");break; case...

How can I correctly do a binary switch statement in java?

java,arrays,list,libgdx,switch-statement
I am working on a game and I need to convert my binary tile id set into a switch statement so I can grab the correct tile from the sprite sheet. I need to convert this list which contains all the possible tiles I would need from 255 to just...

Assigning graph attributes using a function in R using switch()

r,switch-statement,igraph,vertex-attributes
I have a follow up question to the one I asked here. I want to build a function that will assign attributes to a graph based on a certain parameter (called lev in the example below). Here is my toy graph: toy.graph <- graph.formula(121-221,121-345,121-587,345-587,221-587,490,588) and here is a sample function:...

based on the switch case not calling activity properly in android [closed]

android,switch-statement
Hi in the below code when I am clicking general registration report it was showing the last one .when I am clicking the second activity then also showing last activity. Can any one help me from the issue. java public class Reports extends Activity { ListView list; String[] web =...

Why are my buttons in Android not working?

android,button,switch-statement,logout
I have created a menu activity with 3 buttons (main,history,logout). I do not know why all of buttons are not working and there's logout function. Anyway i have no idea about logout function, is it right function or wrong function? I am new to Android, any help will be appreciated....

How to Call Multiple Methods in a Switch Case in Java

java,methods,switch-statement
I'm learning how to build a table in Java with MVC and I am trying to have a switch case that both performs changes to the data in the model and also calls a method like this public void update() { model.fireTableDataChanged(); } to update the data presented on the...

How to output only correct answer for temperature conversion?

if-statement,printing,switch-statement
A simple question but I have tried for a few hours and can't figure the last bit. How can I easily get program to display 'only' the correct answer Celsius or Farenheit, not both? int farenheit(int x); int celcius(int x); int main() { int temperature, converted, converted2; int answer; printf("Temperature...

How to return a value of indeterminate type from a switch statement from a method

c#,switch-statement,return,return-value
I have the following switch statement: switch (SomeType) { case SomeType.A: var data = (Type_1)SomeType.Data; case SomeType.B: var data = (Type_2)SomeType.Data; case SomeType.C: var data = (Type_3) SomeType.Data; case SomeType.D: var data = (Type_4) SomeType.Data; case SomeType.E: var data = (Type_5) SomeType.Data; case SomeType.F: var data = (Type_6) SomeType.Data; }...

Switch case - unexpected behavior [duplicate]

c,switch-statement,case
This question already has an answer here: Switch statement not doing what I expect 4 answers I am working on a project en I tried to make the code more efficient but now there's an unexpected problem with my switch case that I can't seem to resolve. The code...

How do I simplify this VBA switch statement to not repeat so much code?

excel,vba,excel-vba,switch-statement
I am writing an Excel macro that copies information from 1 worksheet and pastes it to another. It has to search for a specific string of text to identify the right column to copy, and I'm using a switch statement to go through the various columns. It's going all the...

Simple VBA Select Case statement not working, Why not?

vba,switch-statement,case
Simple Select Case statement is not working as expected. Message should show this as falling into the "too long" bucket but it comes up as "too short" Lenn = 20 Select Case Lenn Case 7 msg = "You've entered " & Lenn & " digits, this is ok" Case 11...

C++ switch statement odd output

c++,switch-statement
I'm working on a final assignment for an Intro to C++ course. What I've coded so far works, but it's producing some interesting output that I'm looking for clarification on. Here's my code: (Caveat: Yes, I know using void main() sucks, but we're using Visual Studio in class, and this...

Theoretical Coffeescript Switch Statement Conundrum

javascript,coffeescript,switch-statement,theory
preface This probably has no real implementation but after reading another post on coffeescript's 2 switch usages, I decided to play around with it and found this rather odd issue. coffeescript type = 'guidance' s = switch when type is 'guidance' 'g' when type is 'vulnerability' 'v' else 'foo' console.log...

Switch Statement with Enum - Or (||) and (&&)

c#,enums,switch-statement
I'm making a project and I have a question. I have 3 enum states like this: enum GameLevel { Level1, Level2, None, } There's a part in my code where I want to check if there's any level selected or none, so I wanted to do something like: case !GameLevel.None...

how to change text direction to the right slide of switch in android?

android,text,switch-statement
In default mode , text of a Switch sit on the left side of ON/OFF states. i want to change direction of this text to the right slide. how can i do this? I already try this xml code but not working: <Switch android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/switch1" android:layout_gravity:"right" android:layout_margin="@dimen/abc_dropdownitem_text_padding_right" /> ...

Trouble with basic calculator using switch

java,switch-statement,calculator
I have already researched this question, but could not find an answer that solved my problem. I keep on getting output 0. For this assignment, I'm not allowed to use any methods. In my program, 1+2 equals 0 public static void main(String[] args) { int result = 0; Scanner sc...

Not counting right? [closed]

c#,loops,for-loop,switch-statement
I'm trying to get this to count and collect information for different variables using a switch statement however it only counts up to 4. I know I can do this easier with a array. Here's the code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class WeekThreeLab {...

Cannot switchTo frames — keep getting AttributeError

python,selenium,switch-statement,frames
my first time posting. My apologies in advance for any missteps. I am writing in Python, using Selenium, trying to scrape some information from some webpages. I can not seem to solve this puzzle after two days of searching-trying-searching. My issue is this; while trying to sign in to a...

Switch() and foreach() issues in php

php,foreach,switch-statement
I'm trying to put a foreach() inside of a switch. But I got the following error code: Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting case (T_CASE) or default (T_DEFAULT) or '}' in /.../index.php on line 20 I'm getting the $lang value from à $_GET[''] $dir = 'content/'.$lang; $scan =...

Java: if, switch or question mark double point

java,if-statement,switch-statement,condition
Which of the following methods is the fastest? int i; String s; 1. If Else if(i == 0) s = "Case A" else if(i == 1) s = "Case B" else s = "Case C" 2. Switch switch(i) { case 0: s = "Case A"; break; case 1: s =...

Switch Statement Not Handling NS_ENUM values

objective-c,enums,switch-statement
I have an enum defined in a objective-c header that looks like this: #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interface CustomerAndProspectMapViewController : UIViewController<MKMapViewDelegate> typedef NS_ENUM(NSInteger, TypeEnum) { PROSPECT, CUSTOMER }; @end Then in the implementation I have a function that takes a TypeEnum as a parameter and uses a switch to run...

Keep EditText Values after switching layouts

java,android,android-layout,switch-statement
I have an application with 2 layouts which are using the same Activity-Class. In the second layout are some EditTexts, but when type in something and I switch back to the Main-Layout and from there back to the second-layout, the value of the EditTexts are gone. I switch the layouts...

Previous Date SSRS Fix

sql,date,reporting-services,switch-statement
Trying to solve issue with SSRS not showing proper end dates for certain months (i.e. it shows 30th for april fine, then shows 30th for march and then 28th for feb as well as 28th for jan, etc, etc). I have a report that has a "button" that goes back...

Could this shift/jump be faster than switch…case statement?

assembly,x86,switch-statement,emulation,opcodes
I'm trying to optimize a branch (a switch...case like) at its max to emulate an X CPU on an x86 CPU. I thought of this: In memory I'll load blocks of x86 opCodes with a fixed length of 0x100 bytes, like this: first block 0 ...[my code, jump at 0x10000,...

Enum switch - VERY URGENT

arrays,list,for-loop,enums,switch-statement
I have this java class where I am writing the code for applying the overrides. I want to know if using ENUM is appropriate or if I need to use the switch case, how can I use it? Also, I have the for loop that I need to use as...

PHP: Switch() If{} other control structures [closed]

php,if-statement,switch-statement,logic
How do you execute logic with out the use of Switch or If? For instance check_id_switch($id) function check_id_switch($id){ switch($id){ case '1': $HW = 'Hello, World!'; break; default: $HW = 'Goodbye, World!'; break; } return $HW; } Or instance check_id_if($id) function check_id_if($id){ if($id == 1){ $HW = 'Hello, World!'; } else{...

Must the “default” case come last in a switch?

java,switch-statement
In a switch statement in java, is it necessary that the "default" case be the last one? For example, can I do something like the following: switch(x) { case A: ....; default: ....; case B: ....; } ...

How compress switch structure in Java?

java,android,optimization,switch-statement
I have a conditional structure with Switch in Java where I have a lot of cases when the code to execute is very similar. The only one difference is the name of a variable. It's similar to: switch(n){ case 1: tM=getString(R.string.tM1); tD=getString(R.string.tD1); break; case 2: tM=getString(R.string.tM2); tD=getString(R.string.tD2); break; ... case...

Returning an integer to determine which switch statement to show

c++,exception-handling,switch-statement,user-feedback
I'm creating a board game (stratego) in c++ and was wondering if it considered a poor practice to return an integer from a class method in order to determine which case in a switch statement to show to the user. Example: In stratego, you can't attack board pieces that are...

How do I switch() on an array in JavaScript?

javascript,arrays,switch-statement
I have an empty array as follows: var itemsWithEmptySockets = []; Which may be populated with one or more of the following values (depending on information pulled via n API): 0, 1, 2, 4, 5, 6, 7, 8, 9, 15, 16 Where: 0 = Head 1 = Neck 2 =...

Can I use an array in a case statement?

c++,arrays,switch-statement,case
I would like to use an array of const int in a switch/case statement in C++. Is it possible? So far I've tried something like: int main() { int const tab[3] = {1,2,3}; int value(2); switch(value) { case tab[1]: cout << "result is: " << tab[0]<< endl; } return 0;...

Embedded switch in function, how do i retrieve the return value?

ios,function,swift,switch-statement
I'm brand new to 'in depth' OOP and iOS development, so have been getting my hands dirty with it this week. I'm feeling more comfortable so decided to create a rock, paper, scissors game. I'm aware it's very simplistic and any critique on this VERY simple statement is welcome. To...

Initializing variables (int32) inside switch statement [duplicate]

c++,initialization,switch-statement
This question already has an answer here: Why can't variables be declared in a switch statement? 23 answers I have a code block that I'm trying to convert from PHP to C++ and the compiler is getting hung up on my switch statements. I have something along the lines...

SDL: how to get the mouse motion while the left mouse button is down using case statement

c++,switch-statement,mouseevent,sdl-2
I am currently working with SDL2 and am fairly new to it. I am trying to use case statments to get the mouse motion coordinates only while the left mouse button is pressed down. In the end, I need to be able to click on a object and find how...

What restrictions are placed on the values of each case of switch statement

java,switch-statement
For this question i saw a answer like During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value but i didn't understood why because we are also using byte, short, int, char but this statement only...

Breaking from Switch at the right time

java,switch-statement,break
I am doing a sort of non-recursive approach to the Towers of Hanoi. I know that... 1) We move the first disk to the next available space (that is neither the last/current place the disk was in). 2) Move the next possible disk (that is not the first disk). 3)...

Golang switch between structs

struct,go,interface,switch-statement
I'm new to golang and I'm trying to create a function that, based on the struct it's used on, will return a formatted string using Sprintf type Name struct { Title string First string Last string } type Location struct { Street string City string State string Zip string }...

Switch not entering cases but values match [closed]

c#,switch-statement,case
I have an issue with the code below. I have a switch statement that isn't entering any of its cases. Say the value of propType is "ID", the switch should match this to case "id" but it isn't doing so. What have I done wrong? case "button": Button ctrlButton =...

Output is not working in my C program [closed]

c,switch-statement
So I made a Celsius and Fahrenheit Converter in C but I have come across an error in my program. My functions seem to be not working when trying to output the conversion of the temperatures. Could someone show me where I've gone wrong and explain how to fix it?...

Java - Case Looping

java,loops,switch-statement
I was experiment with case statements and I have seem to created an infinite-loop somewhere. I'm not sure why this has occurred. My code loops once and then instead of looping again and asking for another calculated option - it keeps printing out "Unrecognized option..." Could anyone shed some light...

Using combobox with switch statement c#

c#,class,combobox,switch-statement
I am trying to use the switch statement in c# to make some text display in a textbox and a number display in another textbox based on the option I select from a combobox. I have made my own class named 'Devices' and have created several objects within the class....

Switch in Laravel 5 - Blade

php,laravel,switch-statement,laravel-5,blade
How can I use switch in blade templates? When I used: @switch($login_error) @case(1) `E-mail` input is empty! @break @case(2) `Password` input is empty! @break @endswitch in result I see this text as plaintext. I prefer to use switch in few piece of code because it's more clean for me than...

What is wrong with this Ruby case control code? [duplicate]

ruby,switch-statement
This question already has an answer here: Shortcut to make case/switch return a value 4 answers def identify_class(obj) result = case obj when obj.kind_of? Hacker then "It's a Hacker!" when obj.kind_of? Submission then "It's a Submission!" when obj.kind_of? TestCase then "It's a TestCase!" when obj.kind_of? Contest then "It's a...

NameError in dictionary-based switch case

python,dictionary,switch-statement
I have no experience with python, so I thought I'd start looking into it for my new hobby. I'm having an issue when it comes to a switch case, which python doesn't have, after googling I found most use a dictionary style method which you can see below. It's a...

Switch statement with string

java,switch-statement,java-7
I tried the following code: String str = "Str1"; switch(str) { case Constants.First_String : System.out.println("First String"); break; case Constants.Second_String : System.out.println("Second String"); break; default : System.out.println("Default String"); } And my Constants class is, public class Constants { public static String First_String = "Str1"; public static String Second_String = "Str2"; public...

Problems with control flow structures using strings

java,if-statement,switch-statement,control
Below is method that asks for a medium that is either air, water, or steel. If what is entered isn't one of these, the programs ends. If it is a valid medium, it asks for a distance it will travel and calculates the time through each medium. The problem I...

C - Why compare constants with & instead of switch/if?

c,switch-statement,comparison,ampersand,opensl
I am reading the OpenSL documentation for Android. Quoting the following document: http://mobilepearls.com/labs/native-android-api/ndk/docs/opensles/ "Callback handlers should be prepared to be called more or less frequently, to receive additional event types, and should ignore event types that they do not recognize. Callbacks that are configured with an event mask of enabled...

Binary operator '~=' cannot be applied to two UmRet operands

swift,switch-statement
I'm working on integrating an IDTech swiper into my app and I've gotten pretty far along, added the library, registered notifications, unregistered them, and now I'm working on a function that connects the reader. I can't seem to figure out what I'm doing wrong here when I'm attempting to switch...

how to break out of a void method, if not with “return;”

java,switch-statement,break
How do I break out of a void method and get back to the switch method? public static void decrypt() throws FileNotFoundException { Scanner kbrd = new Scanner(System.in); System.out.println("Enter Key-file name: "); String filename = kbrd.nextLine(); System.out.println("Enter Message-filename: "); String mssgFilename = kbrd.nextLine(); String[] keyArray = loadMessage(filename); String[] message =...

Why final Byte as a case in switch statement doesn't compile?

java,switch-statement,constants
byte a = 125; final byte b = 2; final Byte c = 3; switch (a) { case b: // works fine break; case c: // Constant Expression required break; } Since cis a final variable, isn't it a compile time constant and hence a valid case label?...

Is it better to use an array of pointers to members or a switch?

c++,optimization,switch-statement,function-pointers
In my school we're highly encouraged to use arrays of pointers to members instead of switch (or multiple else if) in C++ (and C). As I don't see any point of using such arrays (I actually use maps of pointers to members) instead of a switch statement, I'd like to...

Bypass cases within a switch statement

java,switch-statement,case
I'm attempting to prevent additional cases within my switch statements from printing automatically when located below an initially satisfied case. Here is the code I'm building. I read previously that fallthrough is inevitable in switch statements(?) but I'm assuming there must be a way around this. System.out.println("\nQ1) What is the...

How to Limit a Parameter in a Method?

c#,switch-statement
I have a method that I would like to pass an option to, but as a switch. It is hard for me to explain so I will include the class: class Special { int Var1; int Var2; public void Add1(int option, int variable) { int ToReturn; ToReturn = variable +...

Swap background-color of an specific div with switch/case

javascript,css,switch-statement,background-color
Im trying to swap the background-color of some divs specificly because of their content. The thing is, their background-color should swap when their input is like "Lifestyle" or "Politics" or "Economy" or "Local" or "Sports" or "News". var colorInput = document.getElementById('views-field-field-section').textContent; switch (colorInput) { case 'Lifestyle': document.getElementById('views-field-field-section').style.backgroundColor = '#9518b8'; break;...

Why am I getting an Illegal Token error in my case statement boolean assignment?

javascript,angularjs,switch-statement,angularjs-ng-repeat
I use the same syntax in other switch case statements which work. I basically create an empty object and start adding in key value pairs to it: var vs = $scope; vs.toggleTimeSpan = function(string) { vs.time.span = {}; switch(string) { case '1h': // vs.time.span[1h] = true; vs.time.span.1h = true; break;...

getStringExtra in a switch?

android,android-intent,switch-statement
I have this code: String Tunet = intent.getStringExtra("Tunet"); if (Tunet.equals("Yes") ){ tv22.setText(" okay"); } else { tv22.setText("please answer"); } I want to do this code, in a switch statement, something like this but I don't know how. switch(Tunet.equals) case: Yes // do something case: No // do something case: I...

Does Polymer Dart have something similar to Angular's ng-switch?

dart,switch-statement,polymer
Is there something in Polymer to do a switch statement in markup? I have this component I want to build, and it could have a ton of "IFs" to simply display some code. I was wondering if Polymer has something like Angular's ng-switch? Example: <div ng-switch="selection"> <div ng-switch-when="settings">Settings Div</div> <div...

C++ Why does this work

c++,visual-studio,visual-c++,switch-statement
I am using Microsoft Visual studio 2013 I currently have this switch statement: switch (option) { case 1: getline(cin, newname); cout << "What would you like your new username to be?\nName: "; getline(cin, newname); name = newname; cout << "\nYour username is now '" << name << "' with your...

stuck with switch in c project [duplicate]

c,switch-statement
This question already has an answer here: Why was the switch statement designed to need a break? 8 answers i was trying to write a project in C but it is not working can someone tell me why? and what do i need to change? i am trying to...

Switch Statement: Is the logic different in C v/s. other languages like Java?

java,c++,c,if-statement,switch-statement
I am going through this tutorial on C programming. It says: The switch-statement is actually entirely different(from other languages) and is really a "jump table". Instead of random boolean expressions, you can only put expressions that result in integers, and these integers are used to calculate jumps from the top...

How can I create a new case in switch statement that depends on the previous case

javascript,multidimensional-array,switch-statement,local-storage
Working fiddle of the what I am trying to do : https://jsfiddle.net/wymn7g6s/ The category and products drop down are working using a switch statement. What I want to do is : Add a new case called Wattage. The user selects a product and a respective wattage for that product is...

Endless JavaScript ELSE IF statement 650 Need shortening

javascript,if-statement,switch-statement,iteration,control-structure
I need to modify some script that runs in a program I use. The script ONLY plots horizontal lines at specific prices on a chart that has an X & Y axis. Whenever I switch to a new chart, the script will run through all the statements until it gets...

Swift: Switch case with multiple patterns cannot bind to variable

swift,switch-statement
In the official Swift Programming Language guide, it has this to say about switch case: "...if the case contains multiple patterns that match the control expression, none of those patterns can contain constant or variable bindings." What does it mean by containing multiple patterns?...

PHP print SQL field names as array with corresponding values showing once per row

php,mysql,switch-statement,field
Have a SQL table like this: Titles Device1 Device2 Device3 Title1 inputA inputA inputB Title2 inputA inputB inputC Title3 inputB inputB inputB I want the values inputA, inputB, inputC to each appear once in each row with their corresponding fields, Device1, Device2, Device3, appearing as an array following the "input"...

(How) Can i use 'or' in a switch statement?

javascript,switch-statement
Is the following code right: var user = prompt("Is programming awesome?").toUpperCase(); switch (user) { case 'HELL YEAH' || 'YES' || 'YEAH' || 'YEP' || 'YEA': console.log("That's what I'd expected!"); break; case 'KINDA'||'CANT SAY': console.log("Oh, you'd like it when you'll be a pro!"); break; case 'HELL NO'||'NO'||'NAH'||'NOPE'||'NA': console.log("You can't say that!");...

case operator on for operator

c++,for-loop,switch-statement
for (int i=0; i<3;i++) { switch (i) { case 0: cout << "0"<<endl; case 1: cout << "1"<<endl; case 2: cout << "2"<<endl; } } Why print 0 1 2 1 2 2 ? And not just 0 1 2. I use gcc....

Using Switch for Simple Unity3D Patrol Movement

c#,unity3d,switch-statement
I'm using a switch statement to create two movement types on an enemy: Forward, and Backwards. The enemy has three patrol points. When he begins, I want him moving from the first patrol point and adding 1 to the current point when he hits his second patrol point (empty 3D...

C convert const char * to char

c,string,pointers,char,switch-statement
I searched quite a while to find the answer, but I could only find a solution for C++ that didn't seem to work for C. I'm trying to convert argument of const char * to char to use in my switch statement. I tried various things like strdup(), but was...

How to use a value in switch case?

c#,switch-statement
I pretty new to C# programming so recently I was assigned to do a assignment to calculate the "AverageSpeed" and then match it against the "maxSpeed". I have issue with the "maxSpeed" as no matter what value I key in I will get a "You are within the speed limit"...

Binary operator '~=' cannot be applied to operands of type 'String' and 'String?'

swift,switch-statement,skphysicsbody
I have a simple switch-statement that is not that simple. switch(bubble?.name){ //bubble is SKPhysicsBody case "largeBubble": // <= error newBubbleSize = "medium" break; default: newBubbleSize = "large" break; } Here I get error that I mentioned in title Binary operator '~=' cannot be applied to operands of type 'String' and...

How can I change code this to a switch statement?

java,if-statement,switch-statement
EDIT: Here is the code for the toppings. I'm not sure how to print the names out in the case that more than one topping is selected. public double getToppingCost() { double toppingCost = 0.0; if (creamCheese.isSelected()) toppingCost += CREAM_CHEESE; if (butter.isSelected()) toppingCost += BUTTER; if (peachJelly.isSelected()) toppingCost += PEACH_JELLY;...

Javascript switch statements for form input

javascript,forms,input,switch-statement
Trying to learn some basic JS principles to create a delivery cost calculator based on user input forms and JS switch statements to return a price. (I know this would be easier and more practical with a server database but I would prefer to stick to JS for now) This...

PHP Loose comparison and null on Switch

php,null,switch-statement,comparison,case
Today I saw a strange bug on my code. I have a switch with comparison on case and if my variable equals null or '' it will always comes in the first case. My code : $sHost = filter_input(INPUT_SERVER, 'HTTP_HOST'); switch($sHost){ // Local case strpos($sHost, "dev.localhost") !== false: $this->_sEnv =...

Simple Java Calculator to Solve Expressions

java,loops,arraylist,switch-statement,calculator
I'm working on an calculator that solves expressions. I'm trying to figure out how to how make it calculate in PEMDAS order. I have a for loop to traverse the array list and a switch that calls a class that does the math. I've tried if statements, but haven't been...

Alternative for switch statement, drill down Table Views?

ios,uitableview,swift,xcode6,switch-statement
I need to create a drill down effect with my table views that will expand four table views deep for each of my original cells in my master table view. So far i was successful in populating the master view, and second table view accordingly with this Object Oriented Method,...

Java - duplicate case label

java,intellij-idea,switch-statement
I found some time ago a function to replace polish characters in text with "normal" version of this character. I used this in some projects earlier without problems, but now, when i just copied it, this doesn't want to work. But when I try to compile old projects in the...

some code in swich(..) {…} why set default if default mean to do nothing?

java,switch-statement
switch (Category.categorize(input)) { case MONEY: amount += input.amount(); state = ADDING_MONEY; break; case SHUT_DOWN: state = TERMINAL; // why ??? default: } these codes come from ,my question is : why set default,it's nonsense ?? i think it's good to code like this: switch (Category.categorize(input)) { case MONEY: amount...

Disable an Android Switch

android,modal-dialog,switch-statement
I am developing an app that requires to show a modal window over a switch like the image. In that moment, the user can handle any showed switch. And I pretend to avoid that possibility. I have tried to disable the switch by using setClickable=false and setFocusable=false and nothing works....

Android Getting Fragment ID for use in Switch statement

android,android-fragments,switch-statement
So, I am writing a navigation part of my app and have dynamically created fragments inside an activity. I want, when a user hits either the next or previous arrow, for the app to find out what fragment is in the activity and replace it with either the next or...

Android “Toggle off all buttons”

android,switch-statement,toggle
I am making an app that toggles off and on a switch. I have 4 switches in total and at the bottom I would like to have a button that will toggle them all off at the same time - like an override switch. I'm trying to follow the same...

Declare different type of variables using switch

c#,variables,switch-statement
I am trying to create a new variable based on a particular value received from a function. The variable can be of different classes. Here's what I am trying: switch (request) { case "ClassA": { var x = new ClassA(); break; } case "ClassB": { var x = new ClassB();...

java switch case can not resolve to variable

java,switch-statement
I have a simple switch case case. public static int setMapTile() { int a = getArmadaLength(); // 4 to 6 int b; switch (a) { case 4: System.out.println(" recommended MapSize : 10 x 10"); b = setSize();// method for bigger map, return int break; case 5: System.out.println(" recommended MapSize :...

Java breaking vs returning

java,switch-statement,boolean,break
I am using a boolean that returns true. When something like this happens: public boolean t(String label, String[] arguments) { boolean j = false; if (!j) { return true; } return true; } However, inside of this boolean I have a switch statement. As you may know, you break out...

Switch statement jumps from one case to another

switch-statement,msp430
This is a part of a project for MSP430 microcontroller. My problem is that this switch statement jumps from case 1: (and case 2: as well) to case 11: with no apparent reason. I tried debugging it, the switch value selected_cmd is not changing during the process. The variable selected_cmd...

Ending While loop with blank line(Enter key) inside SwitchCase

java,while-loop,switch-statement,blank-line
*amended input scan I'm trying to end a while loop with enter key/blank line Test codes below works fine. Scanner scan = new Scanner(System.in); String line; while ( (line=scan.nextLine()).length() > 0) { System.out.println(line); } However, when I integrate it within my main program(while loop placed within int switch case within...

stop a nested if loop that is inside a switch method | Javascript

javascript,jquery,arrays,switch-statement
So my friends and I have boon working on an app for the past few days, only issue is that neither of us know JavaScript. It went well until this point. I have learned a bunch from googling but I just can not seem to solve this problem. So we...

Assigned variable empty outside of switch statement PHP

php,variables,scope,switch-statement
public function store($feed) { switch($feed) { case 'full': $coupons = json_decode(file_get_contents('path-to-json-feed'), true); break; case 'incremental': $coupons = json_decode(file_get_contents('path-to-different-json-feed'), true); break; } var_dump($coupons);die(); $this->Deal_model->updateAllDeals($coupons); echo 'Coupons Updated'; } I am trying to assign a value to $coupons but var_dump($coupons) returns an empty array....

Stuck in a switch loop

java,loops,switch-statement
I've written an assignment to try and count the numbers of each type of vowel in a string. It compiles fine, but seems to be looping on the switch statement, and I can't see what I've done wrong, despite about an hour of googling. Please help! =] import java.util.Scanner; public...

Is EnumSet Thread-safe? My test show me it is safe [closed]

java,switch-statement
These is my test code, and the output tells me it is thread-safe. Am I wrong? I think the so-called thread-safety means that the run(){} method is atomic. import java.util.EnumMap; import java.util.HashMap; import java.util.Map; import com.enumTest.enumStateMac.Input; public class TestEnumMapSafe implements Runnable { private String name = ""; public TestEnumMapSafe(String name)...

FizzBuzz doesn't fizz or buzz using case/when

ruby,switch-statement,fizzbuzz
I'm trying to understand how to use a conditional expression in a Ruby case/when statement. This code seems like it should work, but it only prints 1 through 100 inclusive, and never prints "Fizz", "Buzz" or "FizzBuzz". #!/usr/bin/env ruby (1..100).each do |n| case n when n % 3 == 0...