How to store an exception

I want to throw an exception and to display it. In my IF block I throw the exception. Do I have to store the exception to pass it as a variable in the method which precedes. if(count !=0) { throw new Exception(); eventLogger.logError("The count is no

if statement on the tables in R

In a simple way of stating my problem, consider I have the following function: > ff<-function(a){ if (a>0){ return ("positive") } else{ return("negative") } } now: > ff(-1) [1] "negative" > ff(1) [1] "posi

Python: If (user_input) in Dictionary

Having an issue with checking if user input is in a dictionary. Basics of program is there's a shop inventory. The items are stored in a dictionary with corresponding values e.g. {'kettle': 3,.....} Then I want user to write what they want. So if the

Recurrence and if-else statement

I am new to programming. I am trying to use recursion and if-else statement only to print the 99 beers lyrics. Here is my code. How can I make it better to print the lyrics well. The method countdown prints the lyrics while countdownB should print th

Ternary expression PHP / If Statement

I'm learning ternary expressions in PHP and was wondering if someone could verify that the following two blocks of code are the same as far as what is the outcome? $caption = $_POST['caption'] == '' ? NULL : $_POST['caption']; Is the above the same a

Statements on & ldquo; if & quot; not followed

I´m doing a little programming on C with a dsPIC, I have found a little tiny problem that I don´t know why or how is it happenning. Compiler C30 for MPLAB I have this code: int Function1(){ . . . while(1){ . . . P1 = EPC96_1[18]; //Here the value of

If the statement in the linked list does not work as expected

So currently i have an if statement in the GetNth function that im trying to test. but when i inserted a printf function, it made me notice that it goes through the if statement even if the condition is not met, however, when i remove the printf stat

C # If loop in a for loop in a loop if

I would like to reduce this code if I can: class Alarm { internal static void isGreaterThanOrBelowValue(int min, int max, int now, int i) { MainWindow mw = new MainWindow(); if (now < min && now !=0) { if(i == 1) { mw.TxtBox1.Foreground = new S

sql If statement or case

I think I may be missing the obvious here but im trying to create a sql query to pull data out in a particular way but cant work it out. I have a table which is made up with the following columns: Name, StageDate, Stage I want to create in sql an out

C ++ speed and logical flow

I was wondering if there are any speed advantage to doing case B vs case A (or vice versa) in the following: bool test1(){ // Check something, return true/false } bool test2(){ // Check something, return true/false } Case A if(test1() && test2()){

Comparison of file creation dates in VBScript

This may be very obvious to someone out there but I'm having a lot of trouble trying to solve a bug in VBScript. Within the script, I am running through a bunch of .zip files in a directory and processing ones whose creation date is within a specifie

Simple if other onclick then do?

How do I make it so if yes button clicked change colour? Is using .onclick the best option for this? Am I doing it the optimal way? Thanks. html: <body> <div id="box"></div> <button id="yes">yes</button> &

How to use otherwise in this action?

How do you write an if/else statement for this method if there is no result? public ActionResult Search(string q) { Helpers Helpers = new Helpers(); var restaurants = Helpers.getRestaurant(q); return View("_RestaurantSearchResults", restaurants)

The program compiles but does not work

This is an assignment i have to complete. Can someone lead me in the right direction? The program compiles but wont run correctly. The error is InputMissmatch exception.Your problem is that you are entering a letter into a float field. In your progra

if the condition in jsp does not work

I am using the following if condition but it does not work. When the jsp page is loaded the output will be shown without checking the condition. The code is expect to receive the values of a form put them in obj property and send them to Xclass when

java string index out of bounds

I have gone over and over this code and can't see where this is happening it doesn't happen every time it only happens if I run through post twice but I have tried getting rid of each of these in turn by commenting them out and that still gives the e

How to reduce the number of IF statements?

I have many IF sentences that each start a function. Is there an obvious way to write this code much simpler? Every IF starts different function, but it still looks like an overkill. if ($this->machine == '' AND $this->date_from == '' AND $this->

if (: visible) slide upward with a delay

I'm trying to have a page slide down and then another page slide up. But, for some reason, I can't figure it out. http://maximsiebert.com/unamed/Untitled-1.html If you look on here, you can see that if I click the About navigation link, the page slid

Shift Reduce Conflicts in YACC

I m trying the following yacc code and m receiving shift/reduce errors. I m pretty new to this The Purpose of the code is to prepare the syntax for if - else with logical operators also incorporated %{ #include<stdio.h> #include"lex.yy.c"

Bash script comparing file size

I'm running OS X. So I'm having problems with a script to compare a file's size on my local HD, and a server. To do so, I use cURL to get the http header, and trim it to the size in KB. Then I use "stat" to get the local file's size. Here's my c

if statement, selecting a class or element

For example I do have a .className and an element tag. If the user did not clicks on that className or the element tag the alert will run. Please correct my code: var i = $("ul li"); if (!$(this).hasClass("className") || !$(this) == i)

if statement that groups all statements in an if statement

how do you make an if statement that groups all the statements into one if statement at the moment I've got 20 or something if statements which isn't very efficient so i was wondering if there was a way to group the sprites so that if any of my sprit