if-statement

Can if statements be implemented as function calls?

One of the stylistic 'conventions' I find slightly irritating in published code, is the use of: if(condition) { instead of (my preference): if (condition) { A slight difference, and probably an unimportant one, but it occurred to me that the first style might be justified if 'if' statements were implemented as a kind of function ca...

htaccess conditional statements based on server name/path

Is it possible to write some conditional "if" statements in htaccess based on the server name/path? I know I can use <IfModule> but that doesn't solve the problem when the development and production server are identical. thanks ...

Comparing strings in IF statements: unrecognised selector sent to instance...

in my code, I need to compare two strings to see if they are equal. if they are it needs to preform a function. one of the strings is just a @"someString", the other is part of an object. if ([[[mine metal] stringValue] isEqualToString:@"Gold"]) { //some function } however there are some complications when I do this. first, it gives ...

Objective-C: which more efficient -- test IF NOT or just set a variable again?

The current value of a variable may be "X" or "Y". A function needs to make sure it is "X". In general -- with say C integers-- which is more efficient: "if not X, then set to X" "just set it to X anyway" And does that change when the "value" is an Objective-C (immutable) object that has to get re-created? And in both cases is thi...

How to make this if statement in bash

Hi, I'm having a hard time figuring out how to do this if statement. I want to do this: IF (the function has only 1 argument AND $1 is a directory (in the current folder)) OR IF (the function has 2 arguments AND $1 is NOT a directory ) THEN .... END Sorry if it's not very clear, Thanks in advance ...

What is the relative performance difference of if/else versus switch statement in Java?

Worrying about my web application's performances, I am wondering which of "if/else" or switch statement is better regarding performance? ...

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 "%%" ...

Transforming a sequence of tags using XSL

I'm kind of new to using XSL. I'm trying to convert an XML file into another XML file with a different structure using XSL. The input section of the XML goes like this: <tag> <Keyword>Event: Some Text</Keyword> <Keyword>Group: Some Text</Keyword> <Keyword>Other: Some Text</Keyword> </tag> I would like the desired output to...

Grepping complex strings in variables.

All - I am trying to grep for a small string in a much larger string. Both strings are being stored as variables. This code is an example - #!/bin/bash long_str=$(man man) shrt_str="guide" if grep -q $shrt_str $long_str ; then echo "Found it!" fi I don't think variable expansion is working the way I expect it to. I have ...

Adding negative and positive numbers in java without BigInt.

Hi, i'm trying to write a small java class. I have an object called BigNumber. I wrote method that add two positive numbers, and other method that subract two also positive numbers. Now i want them to handle negative numbers. So the i wrote couple of 'if' statements eg. if (this.sign == 1 /* means '+' */) { if (sn1.sign == 1) { ...

whether this php syntax is correct?

hai guys, As i am a newbie i want to check a file path is an image or not <? if(strpos($row['dfilepath'],'jpg') != false) { <img src=" <?= base_url().'/uploads/'.$row['dFilePath']?>" /> } else { <input type="button" onclick="loaddetails('<?php echo $row['dFilePath'];?>');" value="<?php echo $row['dFile...

What are the differences between backtick and single quote? Can I use IF statement in a query as above?

In the codeigniter manual writes the following. $this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement. $this->db->select('(SELECT SUM(payments.amount) FROM paym...

Is it bad practice to use an if-statement without brackets?

I've seen code like this: if(statement) do this; else do this; I don't like that, I think this is cleaner and more readable if(statement){ do this; }else{ do this; } Is this simply a matter of preference or would one way be recommended over the other? ...

as3 conidtional statement not working

Hey, In my code here: var manTimer:Timer = new Timer(1700,5); manTimer.addEventListener(TimerEvent.TIMER, moveMan); function moveMan(e:TimerEvent):void { var manX:Tween = new Tween(man, "x", Regular.easeIn, man.x, man.x - 100, 1.5, true); } function startMan(e:MouseEvent):void { manTimer.start(); var manX:Tween = new Tween...

How do I use PHP to display one html page or another?

Hi! I wanted to use PHP and the if statement, and I wanted to do if ($variable){ display html page1 } else { display html page2 } How do I do this? An please note, that I do not want to redirect the user to a different page. --EDIT-- I would have no problem doing that with one of them, but the other file, it would be too much of a h...

Smallest number that is evenly divisible by all of the numbers from 1 to 20?

I did this problem [Project Euler problem 5], but very bad manner of programming, see the code in c++, #include<iostream> using namespace std; // to find lowest divisble number till 20 int main() { int num = 20, flag = 0; while(flag == 0) { if ((num%2) == 0 && (num%3) == 0 && (num%4) == 0 && (num%5) == 0 && (num%6) == 0 &...

how to suggest gcc compiler more probable branch

Example: if (almost_always_false_condition) { // do something } Is there a way to suggest compiler that in 99% condition will be false. The condition calculation takes ~60 cycles to be checked, and it cannot be calculated at compile time by compiler itself. (gcc 4.3) ...

What's the reasoning behind putting constants in if statements first?

I was looking at some example C++ code for a hardware interface I'm working with and noticed a lot of statements along the following lines: if ( NULL == pMsg ) return rv; I'm sure I've heard people say that putting the constant first is a good idea, but why is that? Is it just so that if you have a large statement you can quickly see ...

LaTeX \newcommand default argument: is empty?

I'm trying to write a simple example command that prints nothing without an argument, but with an argument it surrounds it with something. I've read that the default value should be \@empty and the simple \ifx\@empty#1 condition should do the job: \newcommand{\optarg}[1][\@empty]{% \ifx\@empty#1 {} \else {(((#1)))} \fi } \optarg %...

How to implement language packs in PHP

I created 3 language packs for my site: English, Spanish and French. I am just having trouble implementing them based on user selection. I have the following drop down menu: <select onchange='document.location.href=this.options[this.selectedIndex].value;'> <option>Select</option> <option value="?lang=eng">US English</option> <opt...