if-statement

Prolem with if function

Hi, something seems to be wrong with the first line of this if function, seems alright to me though. if ($count1 == sizeof($map) && $count2 == sizeof($map[0])){ echo ";"; }else{ echo ","; } This is the error I get (line 36 is the first line of the above line.) Parse error: parse error in C:\wamp\www\game\mapArrayConvertor.php on line...

Checking for winner in TicTacToe?

What would be the best way to see (in a 2 player) game of Tic Tac Toe who won? Right now I'm using something similar to the following: if (btnOne.Text == "X" && btnTwo.Text == "X" && btnThree.Text == "X") { MessageBox.Show("X has won!", "X won!"); return; } else // I'm not going to write the rest but it's really just a bunch // ...

How to handle an invalid execution state?

Say you have the following code block: if (Light.On) { // do something... } else if (Light.Off) { // do something else... } else { // this state should never be reached } Now assume that the applications logic dictates that in this part of the code, the last state should never be reached, but it is not something that can b...

Is it safe to rely on condition evaluation order in if statements?

Is it bad practice to use the following format when my_var can be None? if my_var and 'something' in my_var: #do something *The issue is that 'something' in my_var will throw a TypeError if my_var is None.* Or should I use: if my_var: if 'something' in my_var: #do something or try: if 'something' in my_var: ...

Two if statements?

I have two if statements and my project sees one and not the other. Here is the code: If (IsPostBack) Then HandleUploadedFile() End If Dim savePath As String = "Images\ " If (fileUpload.HasFile) Then Dim fileName As String = fileUpload.FileName savePath = Server.MapPath(savePath) + fileName fileUpload.SaveAs(savePath) Me.Lab...

Checking If Then statements in PHP

When I write an if statement, I have it check a variable like so: if(isset($_GET['username']){ echo "set"; } else { echo "unset"; } How could I get my if statement to check if two variables are set similiar to this: if(isset($_GET['username'] & $_GET['firstname'])){ echo "set"; } else { echo "unset"; } So basically how do I c...

POSTGRESQL "IF" syntax error...

Hi guys, I'm new with postgresql, and already have my first problem.. Well, I wrote some code to understand how transactions work, following step by step the manual. To make it short, I've created 2 tables, user and movements: in the first one there are the name, email and credit columns, in the second the columns from, to, import. So...

syntax in expression - Haskell

Im new to Haskell!! I wrote this code: import Data.List inputIndex :: [String] -> [String] -> Bool inputIndex listx input = and [x `elem` listx |x <- input] inputIndex = if inputIndex == true then putStrLn ("ok") It works fine without the if statement but when I put the if statement the following error is shown: Syntax e...

jQuery if statement, syntax

Hey, I'm a little confused about a simple jQuery statement... I want the operation to proceed only if A and B are true. If A isn't true, stop. If A and B are true, then continue. Thanks! ...

Is there a better way to get visual studio to ignore try/catch in debug mode

I want the designer to catch the error when I am debugging and I want the user to see my friendly message if an error occurs for them. I know I can acomplish this with the following: #If Debug=False Then Try #End If 'some code here #If Debug=False Then Catch ex as exception Messagebox.Show("Errors suck") End Try #End If I...

Argument Checking Problem in Bash Script

So basically I am trying to check the arguments that are passed into the script. If it has three arguments and the third argument is a 1, then I want it to continue. I also want it to continue if it has four arguments and the third argument is not a 1. So basically I thought that I could just do... if ([ $# -ne 3 ] and [ "$3" -ne "2"...

Problem with user input in my batch file

Hi, here is the portion of code giving me trouble: IF EXIST TH_BUILD_* ( ECHO A current build of Test Harness exists. set /p delBuild=Delete preexisting build [y/n]?: if "%delBuild%"=="y" (GOTO deleteandcontinue) else ( EXIT) ) For some reason, no matter the input, the batch file exits. Why is this happening (deleteandcontinue is nev...

why isn't this php loop working?!

I have this code: $thisTime = gmmktime(0, 0, 0); for($i=0; $i<=95; $i++) { $perfTimeNumber = ($i+1); $perfTimestamp = $thisTime; $perfTime = date("H:i", $perfTimestamp); echo '<option value="'. $perfTimeNumber .'" selected="'.$sel.'">' .$pe...

Why does my Perl if condition always evaluate to true?

In Perl, I need to read a .conf file that contains either a 0 or a 1. If the value is one, I need to execute whatever is in the if statement. Here is what I have now: open(CONF, "/var/web/onhit.conf"); if(<CONF>) { print "Hello World!"; } close(CONF); The contents of the if statement always evaluate, even if the .conf file contains...

php statements within jquery

Is this bad practice to use php statements such as 'if' within a jquery function? should I really just be writing loads more functions instead of limiting a few using php? it seems to work fine but was wondering if this is a major faux pax? example: this is a code snippet, basically if the php variable $url is equal to 'projects' then...

What's wrong with this function?

Hello, I'm using this function to determine whether my application should be online or offline: function online() { if ($online == "0") { if($_SESSION['exp_user']['userlevel'] != "1") { include("error/offline.php"); exit(); } } ...

JSF <c:if> with different object type

Hello, I'm trying to compare two different object in JSF. A String and an Integer, of cours it don't work... //myVar ==> Integer object //myVar2 ==> String <c:if test="${myVar == myVar2}"> YES!!!!!!!! </c:if> I try with myVar.toString but it's wrong. So how to do it ? Thank's ...

How should I rewrite a very large compound if statement in C#?

In my C# code, I have an if statement that started innocently enough: if((something == -1) && (somethingelse == -1) && (etc == -1)) { // ... } It's growing. I think there must be 20 clauses in it now. How should I be handling this? ...

Conditional Group By statement using LINQ

I have what seems to be a fairly simple requirement, but looking around I'm not able to get a simple answer for this. I have looked on MSDN forums, Exper Exchange and nothing substantial was given to me. I have the following LINQ code Dim SummaryLog As IQueryable(Of clPartCountSummary) SummaryLog = From Inventory In db.tblPartCount...

Using If in JQuery

I'm using the jQuery Clean Calendar Plugin, and it's working well. However, in my jQuery code, I want to check whether any '/' is present in textbox.val(). Then I want to do some operations. How do I check if the value contains '/' in it? ...