ios,swift,if-statement,functional-programming,lazy-evaluation
Do not know if this is what you want,you can use function as a type func foo() { println("this is foo") } func bar() { println("this is bar") } func maybeFooOrBar(isFoo: Bool) { let myFoo = foo let myBar = bar let result = isFoo ? myFoo : myBar result()...
c,if-statement,generator,money
After you have calculated b and adjusted inclusive so it is now 9, you get to your else case, which sets c to 9 (hence the Ninety output) and d to 0, but immediately afterwards sets d to 9 (hence the Nine in the output). I think you mixed up...
In Swift you cannot read a value before it's set, which you're doing here: if Int(randomNum) == guessInt If you change your declaration from this: var guessInt:Int to this: var guessInt = 6 then your code will work as expected (assuming you want the user's guess to be 6)....
jquery,if-statement,html-lists,parent,target
Include the current this reference in the selector, like: $("li").click(function(){ if (down == false) { $(".dropdown",this).css("height", "150px"); down = true; } else if(down == true) { $(".dropdown",this).css("height", "0px"); down = false; } }); The this as a second element in the $(...) makes sure that only child-elements of this will...
if-statement,for-loop,time-complexity,asymptotic-complexity
We can start by looking at the easy case, case 2. Clearly, each time we go through the loop in case 2, one of either 2 things happens: count is incremented (which takes O(1) [except not really, but we just say it does for computers that operate on fixed-length numbers...
python,list,loops,if-statement,compare
I believe you are incorrectly referencing to num instead of line which is the counter variable in your for loops, you either need to use num as the counter variable, or use line in the if condition. def countGasGuzzlers(list1, list2): total = 0 CCount = 0 HCount = 0 for...
jquery,if-statement,intervals,clearinterval
So currently, your code is going to run something like this order: window.intervalcount = 0; // Interval is defined here var interval = setInterval(function () { intervalcount += 1; $("#feedback").text(intervalcount); }, 1000); // will be 0 still if(intervalcount > 5) { clearInterval(interval); } // 1 second after the interval is...
if ($this->$row->level = '3') { ?> <li class=""> <a href="http://example.com/crm/emp_rep1.php">Employee Sales Report</a> </li> <?php } ?> you shouldn't use = operation for equal. should use == or === for equal. by that code you put 3 $this->$row->level and make it's value 3. if ($this->$row->level == '3') { ?> <li class="">...
What if the user needs/wants to enters several values ? You can easily build the query dynamically. By the way, you should use query parameters to prevent SQL injection. // the "where 1=1" allows to always concatenate "and xxx" // instead of testing if there were fulfilled conditions before var...
ruby-on-rails,ruby,if-statement,devise,routes
In Rails access control is done on the controller layer - not on the routing layer. Routes just define matchers for different sets of params and request urls. They are processed before rails even starts processing the request, they don't know anything about the session. Rails could have even used...
sql,regex,oracle,validation,if-statement
Since they all need to match the same Regex pattern, to be alphanumeric, you can validate on the concatenation of these 3 values: IF REGEXP_LIKE(i.TAX || i.NAME || VarTelephone , '^[A-Za-z0-9]+$') However this does not behave exactly as your question condition, since if just one or two of the values...
In the second? example here(VS2015RC) Microsoft is using IIF to illustrate how the If operator is short circuited, so I think IIF is still with us.
The keyword you are looking for is break; break will stop the execution of the loop it is inside. If you are inside nested loops it will only work on the innermost. The opposite of this is continue. Continue stops that iteration and moves onto the next. Here is an...
c#,winforms,if-statement,listbox
if (listBoxEmails.Items.Count >= 0 && listBoxWebsites.Items.Count >= 0 && listBoxComments.Items.Count >= 0) { //perform action } ...
c,if-statement,compilation,generator
You can use nested if else. First check if it is zero dollars, else carry out your process. Try something like this: if (c == 0 && b == 0 && a == 0){ printf("Zero Dollars and ... "); } else{ if (a > 0){ printNum(a); printf("Thousand "); } if...
You need to enclose the blocks of code within parenthesis. @echo off set /p id= Folder Name: set /p yn= Subfolders? (y/n): If %yn% == "y" ( Set rootDirectory = Y:\ md %id% Set rootDirectory = Y:\%id% md %id%\Source md %id%\Work md %id%\PrintFinal ) else ( Set rootDirectory = Y:\...
Since I don't have an example df check if this works for you: do.call("cbind", lapply(err, function(x) if(min(x, na.rm=T) > -20 & max(x, na.rm=T) < 20) return(x) )) ...
a and b cannot be both false after the set of if-else statements. In the first two if's variable a will have the same value than the corresponding hasConditionXXEnabled and b will be set as the opposite. The default else will set both to true. Consider the following code: a...
if-statement,jenkins,jenkins-plugins
You know you can add parameters with default values under Meta Data → [ x ] This build is parameterized → Add parameter, do you? The default values are supposed to be taken if a value for a parameter isn't passed, IIRC. However, you can use the Conditional BuildStep Plugin...
There is nothing wrong with the >=, your problem is that 1 is not really one. Try this Ax >= 1 [1] FALSE Ax == 1 [1] FALSE and format(Ax, digits = 20) [1] "0.99999999999999977796" Edit: A possible Solution As solutions to your problems you can return the final result...
This is a problem of scope. Your code: if (!fileOpenTest) { Excel.Workbook templateBook = excelApp.Workbooks.Open(templatePath); } else { Excel.Workbook templateBook = excelApp.Workbooks[templatePath]; } declares the templateBook variable inside the blocks and thus its scope is limited to within that block. To have the variable persist outside of those blocks you...
You should end the if before you start your else part : int main() { int max = 10; int min = 0; while(cin >> min){ if(min<max){ ++min; //dont understand why do you do this ! cout << "The number inputted is well in the RANGE: " << min <<...
xcode,swift,if-statement,conditional,percentage
You can use arc4random_uniform to create a read only computed property to generate a random number and return a boolean value based on its result. If the number generated it is equal to 1 it will return true, if it is equal to 0 it will return false. Combined with...
PHP does some sneaky things in the if expression. The following values are considered FALSE: the boolean FALSE itself the integer 0 (zero) the float 0.0 (zero) the empty string, and the string "0" an array with zero elements an object with zero member variables (PHP 4 only) the special...
With this statement: string add; You are creating a string variable with the name add, but there is not yet a value assigned to it. So when you compare the variable with the user input, the program will see add as the value null and that is not equal to...
string,excel,if-statement,comparison
We need an Array formula. In G2 enter: =NOT(ISERROR(MATCH(1,--EXACT(F$2:F$7,E2),0))) and copy down. Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. Note: The curly brackets that appear in the Formula Bar should not be typed....
If you don't know if the DataSet is initialized: If ds IsNot Nothing Then ' ... ' End If If you don't know if it contains four tables(zero based indices): If ds.Tables.Count >= 4 Then ' ... ' End If So the final super safe version is: If ds IsNot...
android,if-statement,try-catch
To test for null you should not use globalnidn.equals(null) but rather globalnidn==null ...
Please consider the following formula to resolve your issue: =IFERROR((COUNTIF('Sheet 3'!B4:F4,"N"))/(COUNTIF('Sheet 3'!B4:F4,"Y")+(COUNTIF('Sheet3'!B4:F4,"N"))),0) Regards,...
if-statement,axapta,x++,dynamics-ax-2012,close
You can start your form with the FormRun class and close it again with formRun.close(). Remember to call formRun.wait() when you want the form to remain open and wait for an action from the user. static void openCloseForm(Args _args) { FormRun formRun; Args args = new Args(); args.name(formstr(MyForm)); formRun =...
mysql,sql,if-statement,stored-procedures,cursor
The END IF of the second IF is missing.
Reason: If there is nothing in those textboxes, textbox.Text will return an empty string ("") not null. Solution: Check against "" not null: private void GetHash() { if (txt_sel1.Text == "" && (txt_sel2.Text == "" || txt_sel3.Text == "" || txt_sel4.Text == "" || txt_sel5.Text == "")) { txt_sel1.Text =...
r,if-statement,nested,data.frame,apply
You want to check if any of the variables in a row are 0, so you need to use any(x==0) instead of x == 0 in the ifelse statement: apply(data, 1, function(x) {ifelse(any(x == 0), NA, length(unique(x)))}) # [1] 1 NA 2 Basically ifelse returns a vector of length n...
java,loops,if-statement,while-loop,logic
The second condition should be changed, otherwise the third if won't be reached. Also the third condition should be changed to check if the daysLate variable is greater or equal to zero: if (daysLate > 90) { costDue = bookPrice + 10; } else if (daysLate >= 7) { costDue...
c#,excel,if-statement,for-loop,nested
This happens because the chain of if-then-elses get terminated as soon as you find a positive match, while your loop goes on to try other strings. If you find the right value within the first few constant matches most of the time, the difference may be significant. Adding a break...
osx,swift,if-statement,logic,collisions
In case anyone stumbles across this, here is how I resolved it. let collision: UInt32 = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask switch collision{ case PhysicsCategory.player | PhysicsCategory.floor: playerObj.setJump(true) case PhysicsCategory.player | PhysicsCategory.box: playerObj.setJump(true) case PhysicsCategory.player | PhysicsCategory.wall: return // ect... default: return } ...
javascript,jquery,class,if-statement,jquery-selectors
You can traverse and find the $matches's 'header' element and exclude while sliding up. var $header = $matches.prevAll('li.header'); //hiding non matching lists excluding matches heare $('li', list).not($matches).not($header).slideUp(); ...
ruby-on-rails,ruby,if-statement,flags
It's not that the if is being ignored, but that on each post the flag is being set to true again. The first time you set the flag has to be outside of the iteration, like this: <% flag = true %> <% @posts.reverse.each do |post| %> <% if post.date.day...
php,arrays,json,string,if-statement
You can use substr_count() <?php foreach($soeg_decoded as $key => $val){ $value = $val["Value"]; $seotitle = $val["SEOTitle"]; $text = $val["Text"]; if(substr_count($value, $searchText) || substr_count($seotitle, $searchText) || substr_count($text, $searchText)){ echo '<tr><td>' . $value . '</td><td>' . $seotitle . '</td><td>' . $text . '</td></tr>'; } } ?> Read more at: http://php.net/manual/en/function.substr-count.php ...
If you want to handle an empty result gracefully, check for it explicitly: if [ -z "$result1" ]; then : "ignoring empty string" elif [ "$result1" -ge 0 ]; then printf '%s\n' "$host" else printf '%s\n' "$host" exit fi ...
python,if-statement,conditional
Unless the output from the first line of code is "ar" or "fr" (or something else not in the if-elif conditions), you are over-writing the opt variable. Consider re-naming the 'new' opt to something else, like follows: opt = child.get('desc') extent = child.get('extent') if opt == 'es': opt2 = "ESP:"...
It checks if 'value' is divisible by 7 by giving the remainder i.e 'value % 7' gets the remainder of 'value' by dividing it by 7 if it is equal to 0 ('==7') it will be true. '%' is called the Modulus operator see https://msdn.microsoft.com/library/9f59bza0(v=vs.94).aspx for more info...
excel,if-statement,spreadsheet,calc
something like: if(exact(e4;"bought");i4-f4;if(exact(e4;"sold");f4-i4)) works for you???...
With Java 8 you can write something like: if (Stream.of(">", "<", "&", "l", "p").anyMatch(string::contains)) { ... } Out of curiosity I ran a benchmark to compare this method vs a regex. Code and results below (lower score = faster). Streams perform an order of magnitude better than regex. Benchmark (s)...
c,if-statement,syntax-error,expression
Your code has various syntax errors (If instead of if, semicolon after if-condition). Additionally, your code has a logical problem where you read an int and then compare against a string. This version works and is properly indented: #include <stdio.h> int main (){ int answers_eight[] = {8,16,24,32,40,48,56,64,72,80,88,96}; int answer ;...
c++,string,if-statement,vector
The first line places string beginning with 'abc' at the end, and the second erases them from the vector. auto end_it = std::remove_if(myvec.begin(), myvec.end(), [](const string &str){ return str.find("abc") == 0 ;}) ; myvec.erase(end_it, myvec.end()) ; ...
This is valid according to the JLS. You have: IfThenStatement: if ( Expression ) Statement and Statement: StatementWithoutTrailingSubstatement LabeledStatement IfThenStatement IfThenElseStatement WhileStatement ForStatement Therefore the statement of the first if is the IfThenElseStatement, which is: IfThenElseStatement: if ( Expression ) StatementNoShortIf else Statement A StatementNoShortIf can be a StatementWithoutTrailingSubstatement StatementNoShortIf:...
javascript,jquery,if-statement,click,int
You're thinking about click wrong. It means "When the button is clicked". It isn't a condition that you are testing for at the time the code runs. It is setting up an event handler to run later. So you need to rethink your test: if a button is clicked and...
android,string,if-statement,double
try this String text = "your string"; // example double value = Double.parseDouble(text); hope it helps ...
Just define an array with the terms and use a LINQ expression: string[] searchTerms = { "tree", "water", ...} if (searchTerms.Any(p => word.Contains(p)) { // do something } ...
else { System.out.println(diceNumber); } You are printing the address of diceNumber by invoking its default toString() function in your else clause. That is why you are getting the [email protected] The more critical issue is why it gets to the 'else' clause, I believe that is not your intention. Note: In...
Try moving e.preventDefault(); into the appropriate branch of the if statement for example: $('.touch .mobile-list > li > a').on('click', function(e){ if($(this).parents('li').hasClass('visible-submenu')) { $(this).parents('li').removeClass('visible-submenu'); e.preventDefault(); } else { $('.mobile-list li.visible-submenu').removeClass('visible-submenu'); $(this).parents('li').addClass('visible-submenu'); } }); ...
c#,sql-server,sqlite,if-statement,sqlite3
You can do in one go. Above 2 statements are equivalent to this: SELECT DISTINCT x, y FROM t1 LEFT OUTER JOIN t2 ON t1.id = t2.id AND t2.id = @secondId AND (t1.id = @firstId OR @firstId = '') ORDER BY t1.somecolumn ...
python,if-statement,syntax-error
if statement is indented inwards in for loop. And also = means assignment use == instead for item in data_indices: flag= search_object(item,data,obj_value_min,obj_value_max) if flag == True: #here indent this if one step back file_writer.write('frame0: ' + str(item[0]+1)+' ' + str(item[1]+1) + '\n') ##He ...
The condition is evaluated from left to right, which means intArray[j] < intArray[j - 1] is evaluated first. Therefore if j<=0, you'll get an exception. Changing the order to while (j > 0 && intArray[j] < intArray[j - 1]) { will prevent the exception (assuming the initial value of j...
javascript,jquery,if-statement,onclick
$('a.feature_thumb').click(function(){ $('.' + this.id).addClass('your-class'); }); DEMO...
javascript,html,css,if-statement
It should be as simples as if (window.location.href == 'http://example.example.com/support/default.asp' || window.location.href == 'http://secondurl.com') { } unless I misunderstood the problem....
Sure, here it is: if len(abc) > x and abc[x] == 'fish': dostuff else: dootherstuff and short-circuits, so abc[x] == 'fish' will only be evaluated if len(abc) > x is True. Most languages have a similar operator (e.g. && in C). & is for bitwise "and," and doesn't short-circuit, so...
You probably want this (tested): #!/bin/bash file_upper_case=/root/MASTER.txt file_lower_case=/root/master.txt if [ -e "$file_upper_case" ]; then echo "File is upper-case" echo "Changed to lower_case" mv $file_upper_case $file_lower_case chmod 664 $file_lower_case chown root.dba $file_lower_case elif [ -e "$file_lower_case" ]; then echo "File is lower_case" echo "Change permission only" chmod 664 $file_lower_case chmod root.dba...
Should be: var compare = function(choice1, choice2){ if (choice1 === choice2) { return "The result is a tie!"; } else if (choice1 === "rock") if (choice2 === "scissors") { return "rock wins"; } else return "paper wins"; } Or neater: var compare = function(choice1, choice2){ if(choice1 === choice2){ return "The...
Can you try like: if (intval($line) == intval($rowActual['pid'])) {...} There may be some unwanted characters in the data while reading from file....
As i said in my comment, a loop would be needed here with a boolean flag. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html Placing your While condition at the bottom of the Do loop will insure that the code within the loop is run at least once. If you place the condition at the top like...
java,if-statement,arraylist,try-catch
So, when Inp=sc.nextInt(); fails because the user enters an invalid number, then an InputMismatchException gets thrown. Then you loop again, and eventually attempt to run Inp=sc.nextInt(); again. The problem though is that the invalid number that was entered is still in the input stream waiting to be read. So in...
I tried your code, and it worked fine after I replaced for(int j = 0; j < myvec.size()-1; j++) with for(int j = 0; j < myvec.size(); j++) and myvec.erase(myvec.begin() + j); with myvec.erase(myvec.begin() + j--); My Testprogramm looked like this: #include <iostream> #include <string> #include <vector> using namespace std;...
In binary any numbers LSB (Least Significant Bit) is set or 1 means the number is odd, and LSB 0 means the number is even. Lets take a look: Decimal binary 1 001 (odd) 2 010 (even) 3 011 (odd) 4 100 (even) 5 101 (odd) SO, the following line...
Checking file and/or directory existence To check whether a file exists in bash, you use the -f operator. For directories, use -d. Example usage: $ mkdir dir $ [ -d dir ] && echo exists! exists! $ rmdir dir $ [ -d dir ] && echo exists! $ touch file...
Try this: with c as (select count(*) cnt from table1) select table2.* from table2, c where c.cnt < 1 union all select table3.* from table3, c where c.cnt >= 1 ...
In practice, for only three elements, the Math.max/Math.min solution is probably best. However, when you find yourself labeling variables with numbers like n1, n2, and n3 you should at least consider using an array. The array n in the following has index values 0 through n.length-1, that is, 0, 1,...
You should add the choice == to all of them, not only to the first one. choice = raw_input("> ") if choice == "smack it" or choice == "kick it": print "the tiger gets angrier and eats your head of" exit(0) elif choice == "offer it the beef" or choice...
The show method is blocking in pylab. If you close your gui window, your program will continue. If you do not want it to be blocking, use multithreading (look at the threading module)....
doubleValue can not be nil. A double value of NSString is a simple type (double) and can not have nil as value, so the compiler can not compare them. You can check if your NSString is nil or if the doubleValue is 0.
c,if-statement,compiler-errors,floating-point,floating-point-precision
Because 0.5 has an exact representation in IEEE-754 binary formats (like binary32 and binary64). 0.5 is a negative power of two. 0.6 on the other hand is not a power of two and it cannot be represented exactly in float or double.
I messed around with it for a while and i came up with: 'input if supervisor=fill in supervisor missing Dim fis As Boolean fis = False If UserForm1.superbox.Text = "Fill In Supervisor" Then While Not fis If UserForm1.fillbox.Text = "(Fill In Supervisor)" Or UserForm1.fillbox.Text = "" Then MsgBox ("Please Enter...
This is because your if statement is faulty in this case: else if visits=1 or 2 then band='Low'; You are mistakenly assuming that this is effectively: if visits is 1, or visits is 2 then ... In fact, this is actually: if visits is 1, or 2 is true then...
java,if-statement,while-loop,leap-year
You're on the right track with a while statement. It's pretty simple to keep it from executing infinitely. As soon as the user enters a correct year, the loop condition will evaluate to false and exit. System.out.println("Enter a year after 1750:"); leapYear = in.nextInt(); while(leapYear < 1750){ System.out.println("You have entered...
laravel,if-statement,laravel-4,foreach,blade
You can do: <option {!! ($dev->id == $project_development->developer) ? 'selected' ? '' !!} value="{{ $dev->id }}"> {{ $dev->name }} {!! ($dev->id == $project_development->developer) ? '(Current Status)' ? '' !!}</option> ...
excel,vba,if-statement,excel-formula,excel-match
If I understand this correctly, all we need to do is add an extra array criteria in your LARGE function. You already are getting the 2nd largest based on the customer ID. But we want the 2nd largest based on the customer Id and based on the scheduled date: =LARGE(('All...
string,function,haskell,if-statement,recursion
Your code doesn't handle the case where a line is shorter than the maximum length. This is somewhat obscured by another bug: n is decremented until a whitespace is found, and then f is called recursively passing this decremented value of n, effectively limiting all subsequent lines to the length...
java,if-statement,switch-statement,control
This condition: if (!medium.equals("air") || !medium.equals("steel") || !medium.equals("water")) is incorrect. Replace the || with &&. It might be a bit confusing when you think about it literally but medium can only be equal to one value so you want to make sure that: (medium == x OR medium == y...
python,date,if-statement,for-loop
You can check if the first character in the string is alpha. if date[0].isalpha(): # call your function for German dates here else: # call the other function ...
From what I can tell, your code works fine. This little test script I ran: <?php echo test_title( '' ); echo test_title( 'pdf' ); echo test_title( 'This one works' ); function test_title( $title ) { echo "testing '$title'. "; if( empty( $title ) || mb_strlen( $title, 'UTF-8') <= 3 ){...
xml,function,xslt,if-statement,xpath
Try: <xsl:template match="blabla"> <all> <xsl:for-each select="a"> <a n="{@n}"> <xsl:copy-of select="../b[@n >= current()/@n]"/> </a> </xsl:for-each> </all> </xsl:template> ...
You can use array & loop - <?php $fields = array(); $fields['words'] = get_field('words'); $fields['photography'] = get_field('photography'); $fields['architect'] = get_field('architect'); ?> <div class="panel"> <?php foreach($fields as $key => $value): if($value) ?> <div> <p><span><?php echo ucwords($key);?></span><span><?php echo $value;?></span></p> </div> <?php endif; endforeach;?> </div> ...
You can use All: if(Enumerable.Range(0, 9).All(c => excel_getValue("A" + (i + c)) == "")) { } ...
jquery,ruby-on-rails,search,if-statement
The standard way to use a search would be to include a parameter in the URL. That way you can have a similar to if user_signed_in? check for the parameter: if params[:search].present?.
You just need to extend the logic within the All: if (!(key.All(c => char.IsLetterOrDigit(c) || c=='_'))) ...
r,if-statement,recursion,vector,integer
Your sapply call is applying fun across all values of x, when you really want it to be applying across all values of i. To get the sapply to do what I assume you want to do, you can do the following: sapply(X = 1:length(x), FUN = fun, x =...
$vocals = array('a','e','i','o','u'); if (ctype_alpha($original) && in_array($original{0}, $vocals)) { print "oké"; } else { print "pas oké"; } With $string{index} you could access to a char into a certain position into $string. With in_array you could check if that letter is contained into an array (in our example, vocals array)...
Here is the formatted and corrected code: import datetime now = datetime.datetime.now() print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour,now.minute, now.second) print "Welcome to the beginning of a Awesome Program created by yours truly." print " It's time for me to get to know a little bit about you" name...
java,if-statement,while-loop,int,logic
Try setting min and min2 to Integer.MAX_VALUE. Practically this should solve your problem because the data type of integers you are working with is int. But theoretically, setting min and min2 to the first input value is the correct solution. EDIT: As a matter of fact, I see that you...
Your parenthesis are unbalanced. Try: =IF(OR(AND(B2>=Sheet3!$B$4,B2<=Sheet3!$C$4),AND(B2>=Sheet3!B6,B2<=Sheet3!C6)),"Blue","Grey") ...
You can try that with an approach involving two calculated fields. Assuming that your big_city, small_city calculation is a calculated field named City_Size Now, the First Calculated field will assign a 1 or 0 to each row, depeding upon the value of City_Size. Name it as is_big_state if City_Size =...
javascript,html,string,if-statement,condition
Your code, onclick=match() should have quotes (i.e. onclick="match()"), though you'd be better off using the standard of attaching a click event in your javascript. Further, as pointed out by Teemu above, 'popwindow' is not a function unless you have specified it elsewhere in your script. I have a feeling your...
Sounds like you want Resolve-Path: if(($Paths = @(Resolve-Path "C:\Test6_*_15.txt"))){ foreach($file in $Paths){ # do stuff } } else { # Resolve-Path was unable to resolve "C:\Test6_*_15.txt" to anything } ...