if-statement

Why is "else" rarely used after "if x then return"?

This method: boolean containsSmiley(String s) { if (s == null) { return false; } else { return s.contains(":)"); } } can equivalently be written: boolean containsSmiley(String s) { if (s == null) { return false; } return s.contains(":)"); } In my experience, the second form is se...

Please recommend a smart, elegant way to write these repetitive 'if' statements in php

Hi PHP users, I just know i'm doing this in really bad way: $url = wp_get_referer(); $path_parts = pathinfo($url); $mycat = $path_parts['filename']; if ( $mycat == "animation" ) { $_SESSION["theCategory"] = $mycat;?> <a href="<?php bloginfo('home')?>/c...

RoR: Why is this if-statement failing?

Why is the second if statement failing in the following code block? The output from the console indicates that the private parameter is 0, so it should be passing? The private parameter is from a checkbox in the new form, that I'm using to set a boolean field in the model. if (((params[:note])[:text]) != "") logger.debug("passed first...

How do I check if a number in a textbox is greater than a predefined value

Hello, im doing an exercise where i have to make a parking lot application. The objectives are: Create a form with a numericUpDown control for choosingthe amount of time a vehicle was parked. Add option buttons to show if the vehicle is a car or truck. Clearly label each box and button. Add a label or text box to show the amount to pay....

Detecting browser with JQuery

Hi Guys, I am trying to use jQuery(document).ready(function () { if (!jQuery.browser.msie <= 7.99) { jQuery('#element').css('display', 'block'); } }); But it doesn't appear to work ? What am I doing wrong ? Thx Edit: Use conditional comments <!--[if !IE]> <!--[if lt IE 8]> //do stuff <![en...

Checking a string to see if it contains numeric character in UNIX

Hi, I'm new to UNIX, having only started it at work today, but experienced with Java, and have the following code: #/bin/bash echo "Please enter a word:" read word grep -i $word $1 | cut -d',' -f1,2 | tr "," "-"> output This works fine, but what I now need to do is to check when word is read, that it contains nothing but letters and ...

If statements within a Linq where clause

Hello all. Struggling a bit today. I have the following method that returns a list of products..lovely. public static List<tblWeight> GetProductInfo(string memberid, string locationid, string basematerial, string source) { MyEntities getproductinfo = new MyEntities (); return (from p in getproductinfo...

Is this an OK test to see if a variable is set

Hello, Yesterday, I posted an answer to a question that included several (unknown to me at the time) very bad code examples. Since then, I've been looking at my fundamental knowledge of PHP that allowed me to think that such code is possible. This brings me to a question that I can't seem to find an answer to: If I want to check for ...

Why does using an If statement change a variable?

I am reading a text file and processing some records, a relevant sample of the text file is #export_dategenre_idapplication_idis_primary #primaryKey:genre_idapplication_id #dbTypes:BIGINTINTEGERINTEGERBOOLEAN #exportMode:FULL 127667880285760063715151750 127667880285760123715151751 I want to perform a specific action when application_i...

If a > 0 or a = 0 & b < 0 or b = 0 Statement isn't working how it should be

I'm new to ASP (new job uses a windows server and I've only used Linux before) and I'm building a 'log' that stores it's data into XML files. I've got it reading the XML out perfectly but now I'm trying to get it to print out data from a specific range of dates. The way I'm doing this is by using the DateDiff function to compare the dat...

C# if statement syntax with list of objects

I have a list of objects, called Attributes, that, essentially, i need to do the following in C# <pseudocode> if (list.Contains(Attribute where getName() == "owner")) { do stuff } </pseudocode> the problem I'm having is the nested bracket bit of the if - "Attribute where getName() == "owner". This is my code - it doesn't work, obvi...

In C++ syntax, can the condition of the if else, return a int and still execute the statements within

Here is the code which compiles : int select_object = 0; if( select_object ) //condition returns an int { printf("Hello"); } if condition returns an int and not a boolean will the hello be printed ? When I tested this it printed hello. Any idea why even for an int it executes the print statement. THanks ...

Ternary operatory for the stament

if( $a == $b) { return true;} else { return false;} how to write a ternary operater for the following ? is this the way if($a == $b)? return true; : return false; ...

Objective-C parser problems with and static getter-function

Hi there, I've created a static getter-function: @implementation MyClass static int aValue = 1; + (int) aValue { return aValue; } // other stuff here @end and now I'm trying to access it in some different ways from another class: @implementation AnotherClass - (void) aMethod { if (MyClass.aValue > 0) { NSLog(@"Foobar"); } //...

How to make large if-statement more readable

Is there a better way for writing a condition with a large number of AND checks than a large IF statement in terms of code clarity? Eg I currently need to make a field on screen mandatory if other fields do not meet certain requirements. At the moment I have an IF statement which runs over 30 LOC, and this just doesn't seem right. if(!...

Messed up method - if/then structure and string manipulation problems

I have a method that gets called any time a control on my view changes and should update a UILabel. It has two UITextFields and two UISliders. First I check to see if either of the UITextFields are empty and if so, advise that they need to be filled in. Otherwise I get the difference between the UITextFields' values and generate a cou...

If statement in javascript forms

Hello Im fairly new to javascript but have some experience in HTML. I am trying to create a form which allows me to select an option from the drop down menu, which further expands the form (showing new fields on the same page) depending on the option selected from the drop down menu. I figured I need some sort of if statement to achieve...

What variable is changing?

Hi, Please tell me what variable is changing on the loop so I can maybe create a if else statement. I'm not a developer so, I really need help. Here's the code $(document).ready(function(){ $("#health").show(); $("#health").hide(); $("#billing").hide(); var arr = [ $("#pension"), $("#health"), $("#billing") ]; var cur = 0...

How to carry "getjson" functionality from one func to another?

Basically I have a getjson call to call for a bunch load of data. Now I am getting sick of the amount of if data is null else checks. For Example: if (data.Height == "") { $('#DataHeight').html('No Data is Available'); } else { $('#DataHeight').html(data.Height); } Reason being ...

Help with JQuery conditional statement

I am trying to run some JQuery script on a particular page but only if a certain page loads. The Scenario: We have one page that loads (i.e., webpage.aspx) and it loads different content based on the referring click. (i.e., webpage.aspx?contentId=1, webpage.aspx?contentId=2, webpage.aspx?contentId=3, etc). Here is my problem. I need ...