if-statement

Which is better a switch statement or if-else if-else statement?

Possible Duplicates: is else if faster than switch() case ? What is the relative performance difference of if/else versus switch statement in Java? I am just wondering if one is better (i.e. more efficient). To me the seem to be the same other than the syntax. ...

Bourne: if statement testing exit status

What is the difference: if IsServerStarted ; then ... and if [ IsServerStarted -eq 0 ] ; then ... Seems to me that these two statements should be equivalent? Strangely the second statement is always true. ...

how do i get the id under another id in an if statement?

how do i get the id under another id in an if statement? $('#mainmenu').mouseenter(function () { if ( $(this).???('#a')) { } if ( $(this).???('#b')) { } }); <div id="mainmenu"> <div id="a"></div> <div id="b"></div> </div> ...

XSL testing empty strings with <xsl:if> and sorting

I am having trouble with a template that has to check 3 different nodes and if they are not empty, print the data I am using <xsl:if test="string-length(node) != 0"> for each node then doing the output but it is not printing anything. It is like the test returns zero. I have selected the parent node of each node I want to check the le...

Using an object in an if statement... (Android)

I have an object variable Object test = Spinner.getSelectedItem(); -It gets the selected item from the Spinner (called spinner) and names the item 'test' I want to do an if statement related to that object e.g: 'if (test = "hello") { //do something }' But it appears not to work.... Can someone give me some help? -Do I have to use a ...

PostGres if query?

Is there a way to select records based using an if statement? My table looks like this: id | num | dis 1 | 4 | 0.5234333 2 | 4 | 8.2234 3 | 8 | 2.3325 4 | 8 | 1.4553 5 | 4 | 3.43324 And I want to select the num and dis where dis is the lowest number... So, a query that will produce the following results: id | num |...

Change Stylesheet via If in php

Hey i have a question. At the moment i'm trying to use a stylesheet which i get through a if. but it doesn't do anything. here is my code at the moment. the variable $stylesheet will be variable but while testing i've setted it to normal <?php $stylesheet = 'normal' if($stylesheet = 'small') { $style = './sitestyle/styles...

Simple IF statement question

How can I simply the below if statements? if ( isset(var1) & isset(var2) ) { if ( (var1 != something1) || (var2 != something2) ) { // ... code ... } } Seems like this could be condensed to only one IF statement but am not certain if I'd use an AND or OR ...

Using Container.DataItem with an If statement within <% %>

I have the following code in a c# aspx page: <ItemTemplate> <a <% if(((Dictionary<string, string>)Container.DataItem)["type"]==Session["type"]){%> class="active"<%}%> This code is causing the following error. Compiler Error Message: CS0117: 'System.ComponentModel.Container' does not contain a definition for 'DataItem' Why is th...

Problem comparing keys in Appengine/Python

I'm trying to create a relationship between "tables" with Appengine/Python. Imagine I have a "table" for items, and a table for colors. I save the color of an item by saving the color key as an atribute of the item. That's working well, but this particular piece of code is not working: <select id="colorKey" name="colorKey"> {% for c...

Test for a dot in bash

How can I test if some string is dot in bash? I've tried this: if [ "$var" = "." ] and this: if [ "$var" = "\." ] But it doesn't work. ...

Dropdown list with a "Select All" option

I have three dropdown boxes, Region, District, and City. I want my District dropdown to have a "Select All" option so the user can get all Cities in the Region, else just display the City based on the selected District. My query looks like this: IF @district =-2 THEN (SELECT DISTINCT city FROM myTable WHERE RIGHT(Region, 3) = ?) ORD...

Can you use #defined values in if statements (In C programs)?

I am new at C programming. I thought when you type something like #define Const 5000 that the compiler just replaces every instance of Const with 5000 at compile time. Is that wrong? I try doing this in my code and I get a syntax error. Why can't i do this? #define STEPS_PER_REV 12345 ... in some function if(CurrentPosition >= STEPS_PE...

Source operator doesn't work inside parenthesis in bash

I'd like to include a config file in my bash script with 2 conditions: 1) the config file name is constructed on-the-fly and stored in variable, and 2) in case if config file doesn't exist, the script should fail: config.cfg: CONFIGURED=yes test.sh: #!/bin/sh $CFG=config.cfg echo Source command doesn't work here: [ -f $CFG ] && ( ...

PHP: Assigning values to a variable inside IF statement

Hi guys, I was wondering if i could assign values to a variable inside an IF statement. My code is as follows: <?php if ((count($newArray) = array("hello", "world")) == 0) { // do something } ?> So basically i want assign the array to the $newArray variable, then count newArray and check to see if it is an empty arra...

MySQL JOIN with IF conditions.

Hi, I want to get some results via query simillar to: SELECT * FROM users LEFT JOIN IF (users.type = '1', 'private','company') AS details ON users.id = details.user_id WHERE users.id = 1 Any ideas? ...

Refactoring a complicated if-condition

Hi all, Can anyone suggest best way to avoid most if conditions? I have below code, I want avoid most of cases if conditions, how to do it ? any solution is great help; if (adjustment.adjustmentAccount.isIncrease) { if (adjustment.increaseVATLine) { if (adjustment.vatItem.isSalesType) { entry2.setDebit(adjustmen...

Input accepting char when it should be string?

I am new to C++ and am making a simple text RPG, anyway, The scenario is I have a "welcome" screen with choices 1-3, and have a simple IF statement to check them, here: int choice; std::cout << "--> "; std::cin >> choice; if(choice == 1) { //.. That works fine, but if someone enters a letter as selection (instead of 1, 2 or 3) it'll...

c#: can you use a boolean predicate as the parameter to an if statement?

In C#, can you use a boolean predicate on its own as the parameter for an if statement? eg: string str = "HELLO"; if (str.Equals("HELLO")) { Console.WriteLine("HELLO"); } Will this code output "HELLO", or does it need to be: string str = "HELLO"; if (str.Equals("HELLO") == true) { Console.WriteLine("HELLO"); } If there is ...

Script to drop an index if it exists that works in SQL Server 2005 AND SQL Server Compact 3.5

I have an application with a rather long chain of upgrade scripts. The application works in SQL Server 2005 - I'm trying to upgrade it so it will also work in SQL Compact 3.5 Part of the script involves dropping old indexes if they exist. I REALLY want to have one script that can handle both scenarios. I've been having a lot of success...