if-statement

consecutive if's in PHP

Hi, I'm doing some validation now in PHP, and I'm running allot of conditional statements, for example: if ($this->email->isValid($email)) return false; if ($this->username->isValid($username)) return false; ect.. Is there a nice way to do this? Or do I just run ten If statements like the ones above? I can't use switch obviously,...

Python and if statement

I'm running a script to feed an exe file a statement like below: for j in ('90.','52.62263.','26.5651.','10.8123.'): if j == '90.': z = ('0.') elif j == '52.62263.': z = ('0.', '72.', '144.', '216.', '288.') elif j == '26.5651': z = ('324.', '36.', '108.', '180.', '252.') else: z = ('288.'...

How to change form text with Jquery but keep it when filled by user?

Hi! (I hope my title is comprehensible, it was hard to sum up.) I have some script which change some text inside a form depending on the selected radio button as you can see here: http://jsbin.com/onowu/ The problem is that if some user enter some text and then click on a other radio button it will remove his text. What I'm looking f...

How to indent long conditionals for 'if' statements?

My question relates to this previous question, but the solutions offered don't address the problem I have outlined below. After a google search I haven't found any code style guidelines that address the specific problem of long conditionals in an if statement like this. if( isNull(value1) || isToLong(value1) || hasBadFormat(valu...

Java: If vs. Switch

I have a piece of code with a) which I replaced with b) purely for legibility ... a) if ( WORD[ INDEX ] == 'A' ) branch = BRANCH.A; /* B through to Y */ if ( WORD[ INDEX ] == 'Z' ) branch = BRANCH.Z; b) switch ( WORD[ INDEX ] ) { case 'A' : branch = BRANCH.A; break; /* B through to Y */ case 'Z' : branch = BRANCH.Z; brea...

Ruby a clever way to execute a function on a condition

Hey, As a bit of a fun project I'm implementing a Beatnik interpreter in Ruby. If you've never heard of Beatnik it's an esoteric programming language in which operations are specified by the "scrabble score" of the words in the source code. Anyway, the implementation requires a different operation to happen for different scrabble score...

multiple instance if statement in xcode (iphone)

what is the proper way to do If statement with two variable in Xcode for Iphone currently I have if (minute >0) && (second == 0) { minute = minute - 1; second = 59; } ...

iPhone: I'm trying to use an if statement but it's not working for me.

(Nearly solved, but not quite) (My temporary solution is to use a void method and call it in every button, and in that way I can edit the code used by multiple buttons rather then when making improvements having to edit each individual buttons if statement) I bet it's a really simple error i've made, but I can't find it. I'm trying to ...

Number guessing game - how to?

how do i make this so once the user inputs a number and presses enter(or something) it runs the if else statements! please help! public static void main(String[] args) { System.out.println("please guess the number between 1 and 100."); boolean run = true; int y = 0; Random ran = new Random(); int x = ran.nextInt(99); while (ru...

To make a if-clause in Sh

I have the following in a file which is sourced both by .bashrc and .zshrc. The syntax is from the site. if $SHELL=/bin/zsh then # to not java .class when running java myclasslist () { reply=(${$(ls *.class)%.class}) } compctl -K mycl...

if else .htaccess/ISAPI

I would like to check a URL to see if it contains one of multiple strings, and then based on that, send it to a different URL. Am I forced to use multiple lines, one for each possibility? Or is there anyway to form an if statement? I figured that something like this should work: (string1)(string2)(string3) example.com/$1$2$3 because in...

How to resume program (or exit) after opening webbrowser?

I'm making a small Python program, which calls the webbrowser module to open a URL. Opening the URL works wonderfully. My problem is that once this line of code is reached, the problem is unresponsive. How do I get the program to proceed past this line of code and continue to execute? Below the problematic line is the problematic line, ...

Java application if/case recommendation

I am writing an application for a Java course. I am a complete beginner and am just going off material I have learned from the course and from the web. The application is exhibiting some behavior and I am not sure what is causing it. The application is GUI based and does calculations on user input. For the action listener section, I hav...

MySQL View check if data is NULL

I need to put a Case in the Select to check if the Data I'm adding to my view is NULL, in which case I want it to just enter a zero, or not. ...

Is it possible to make an object return false by default?

Hey Stackfolk, I tried to ask this before, and messed up the question, so I'll try again. Is it possible to make an object return false by default when put in an if statement? What I want: $dog = new DogObject(); if($dog) { return "This is bad;" } else { return "Excellent! $dog was false!" } Is there a way this is possible? ...

CI PHP if statement w/ sql syntax

This is a quick syntax question... I need to block out an HTML element if two SQL statements are true w/ php. If the status = 'closed', and if the current user is logged in. I can figure out the calls, I just need to see an example of the syntax. :) So, If SQL status=closed, and if current_user=is_logged_in()...something like that. ...

If statement simplification in C#

I have a line of code that looks like this: if (obj is byte || obj is int || obj is long || obj is decimal || obj is double || obj is float) Is it possible to write something more elegant than this? Something like: if (obj is byte, int, long) I know that my example isn't possible, but is there a way to make this look "cleaner"? ...

Do all programming languages have boolean short-circuit evaluation?

In the PHP code if(a() && b()) when the first argument is false, b() will not be evaluated. Similarly, in if (a() || b()) when the first argument is true, b() will not be evaluated.. Is this true for all languages, like Java, C#, etc? This is the test code we used. <?php function a(){ echo 'a'; return false; } function b(){ e...

Wrong logic in If Statement?

$repeat_times = mysql_real_escape_string($repeat_times); $result = mysql_query("SELECT `code`,`datetime` FROM `fc` ORDER by datetime desc LIMIT 25") or die(mysql_error()); $output .=""; $seconds = time() - strtotime($fetch_array["datetime"]); if($seconds < 60) $interval = "$seconds seconds"; else if($seconds < 3600) $interval ...

objective-c if statement

So this is probably really simple but for some reason I can't figure it out. When I run the below code I can't get it to go into the if statement even though when I go into the debugger console in xcode and I execute po [resultObject valueForKey:@"type"] it returns 0. What am I doing wrong? Thanks for your help! NSManagedObject *resu...