if-else-statement

Why the switch statement and not if-else?

I've been wondering this for some time now. I'm by far not a hardcore programmer, mainly small Python scripts and I've written a couple molecular dynamics simulations. For the real question: What is the point of the switch statement? Why can't you just use the if-else statement? Thanks for your answer and if this has been asked befo...

PHP If else statement that a database record is empty it will display a default picture.

Hi basicly I am trying to create a simple IF statement that shows a default picture if one hasn't been entered in to my database. I am using server to store my picture and a database to store the file name, so I can get the image to display if it has a file name in the db but I want the If statement to say if the record is empty display ...

Evaluation of an IF statement in VB.NET

For the following If-statements in VB.NET, what will be the sequence in which the conditions will be evaluated? Case 1: If ( condition1 AND condition2 AND condition3 ) . . End If Case 2: If ( condition1 OR condition2 OR condition3 ) . . End If Case 3: If ( condition1 OR condition2 AND condition3 OR condition4) . . End If ...

How to correctly format PHP 'IF ELSE' statements?

It's been a long running issue that I've come across in many-a-hot-and-steamy coding sessions. One person codes this way another codes that way. So after much push and pull I'm curious... Is there any correct way of phrasing a PHP 'IF ELSE' statement? Personally I use the: if ($variable == 'setvalue') { $variable = executefunction...

error with printf statement? (In C) *Update*

For clarification purposes I need the program to print the numbers that are input for a and b, not the actual letters a and b. Okay here's the revised program per yall's suggestions: int main (int argc, char *argv[]) { int a; /*first number input*/ int b; /*second number input*/ a = atoi(argv[1]); /*assign to a*/ ...

Checking site and deciding then CSS style?

I aim to have a similar Bar at the top as here: http://www.keltainenporssi.fi/ The colour of the current site is in red, while other sites are in black. How would you reach my aim? Perhaps by php? The syntax in pseudo-code may be if $site = A use-styleA if $site = B use-styleB else use-FinalStyle ...

If else alternative

I have a program I am writing that works on the principle of populating a two dimensional array to check the winning condition, it's noughts and crosses so the two dimensional array is populated on the click of a button, 1 for a circle, 2 for a cross, then the checkWin() will work on this principle, not the actual code... if (myArray[0]...

PHP Parse Error

I am trying to add an echo statement after the line: echo '<td class="today" valign="top"><a class="monthnav" href="dayPlanner.php?d='.$day.'">'.$day.'</a></td>'; It is just a simple echo ''; (Really I am trying to break the line up to not include the in the same echo statement, so I can insert some more code later. I however am ge...

Populating A Page with XML and Javascript/Jquery, checking if the url is the same as an xml tag

Hi, I need to create a javascript function that will write a page based on the url, so basically I am trying to create a javascript function that will check the url, and find the corresponding xml item from there. The reason behind this is so that the html page can just be duplicated, renamed, and the xml updated, and the page will fill...

"else" considered harmful in Python?

In an answer (by S.Lott) to a question about Python's try...else statement: Actually, even on an if-statement, the else: can be abused in truly terrible ways creating bugs that are very hard to find. [...] Think twice about else:. It is generally a problem. Avoid it except in an if-statement and even then consider do...

Wordpress php: Way to test if pages are children of a parent page?

Hi - Working on my first Wordpress site so I'm sure this is a really basic question. I'm struggling to write a conditional php statement that performs a certain action when a page is a child of a parent page. For example, rather than just specifying one page, as below, I'd like to specify all pages that have the 'About Us' page as a pa...

if else statement not working!

This code has no errors in it, but when i click the button nothing in the "if" statement works! it doesn't crash or show errors... Btw im working in Xcode on an iphone app. #import "MainView.h" @implementation MainView @synthesize MyButton2, MyMainTextLabel; @synthesize MyButton3, MyMainTextLabel; @synthesize MyButton2, Button2Lab...

Another simple "if-else" form in PHP?

Hi, i read somewhere before, there is another way to perform the if-else statement, the code should be similar to this: <?php $var = "stackoverflow"; // Here is the if-else if(strlen($var) > 1) ? echo "TRUE" : echo "FALSE"; ?> I could only remember something like this, but it doesn't work, anyone knows how to write this 1 line i...

How to structure an if-else statement in an IBAction method

I don't know how to make an if-else statement within an IBAction! I can only make them in the button clicks... what I want it to do is check for which # the int question is at and make the appropriate changes. please help! MainView.h #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> @interface MainView : UIView{ IBOutlet U...

General programming - else or else if for clarity

In a situation where a variable could have two different values, and you do something if its one, something differnent if its the other, would you just do: if(myVariable == FIRST_POSSIBLE_VALUE) { ... } else { ... } or would you do: if(myVariable == FIRST_POSSIBLE_VALUE) { ... } else if (myVariable == SECOND_POSSIBLE_VALUE) { ... } ...

Can all language constructs be first-class in languages with offside-rules?

In LISP-like languages all language constructs are first-class citizens. Consider the following example in Dylan: let x = if (c) foo(); else bar(); end; and in LISP: (setf x (if c (foo) (bar))) In Python you would have to write: if c: x = foo(); else: x = bar(); Because Python desting...

PHP Conditional Logic

In PHP, is the following logic allowed If (x && y) //Do A Elseif (x) // Do B Elseif (y) // Do C Else // Do D Basically, are you allowed to use more than one elseif? ...

Why can't R's ifelse statements return vectors?

I've found R's ifelse statements to be pretty handy from time to time. For example: > ifelse(TRUE,1,2) [1] 1 > ifelse(FALSE,1,2) [1] 2 But I'm somewhat confused by the following behavior. > ifelse(TRUE,c(1,2),c(3,4)) [1] 1 > ifelse(FALSE,c(1,2),c(3,4)) [1] 3 Is this 1) a bug or 2) a design choice that's above my paygrade? ...

Groovy 1.5.x / Grails 1.0.x If-Else statement bug

I have this code in a Grails 1.0.4 Groovy console: def devices = Device.getAll() def found = devices.findAll { if(it?.localNumber && it?.areaCode){ def pattern = ~".*${it.areaCode + it.localNumber}" def matches = "$msisdn" ==~ pattern println "$matches == msisdn: $msisdn ==~ pattern: $pattern" matche...

Explicit or implicit execution control statement use

I sometimes use if (this._currentToolForeColor.HasValue) return this._currentToolForeColor.Value; else throw new InvalidOperationException(); other times I use if (this._currentToolForeColor.HasValue) return this._currentToolForeColor.Value; throw new InvalidOperationException(); The two are equivalent, I know, but I am...