Menu
  • HOME
  • TAGS

Lazy functions evaluation in swift

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()...

Why does my program give me the excess output? C program

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...

Swift If program

swift,if-statement,random

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 target div inside clicked

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...

Time complexity of if-else statements in a for loop

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 - Using a created list as a parameter

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 - clearInterval seems not to work

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...

using if else with codeigniter return value

php,codeigniter,if-statement

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="">...

Several nested if conditions

c#,if-statement

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...

Rails Devise Routes: If user signed in, point to index. Else, point to new user session

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...

Oracle regular expression REGEXP_LIKE for multiple columns

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...

If and only if in vb.net 4?

vb.net,if-statement,.net-4.0

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.

c# nested if/else in a for loop

c#,if-statement,for-loop

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...

How to make if statement that checks if multple listBoxes are empty or not?

c#,winforms,if-statement,listbox

if (listBoxEmails.Items.Count >= 0 && listBoxWebsites.Items.Count >= 0 && listBoxComments.Items.Count >= 0) { //perform action } ...

How to make my if statement output the correct printf C program

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...

My batch files if else statement isn't working

batch-file,if-statement

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:\...

How to deal with NA when using lappy in R

r,if-statement,na

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) )) ...

Simplify multiple if-else statements for unit testing

java,if-statement

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...

Jenkins Flexible Publish plugin if else condition

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...

>= not working, R [duplicate]

r,if-statement,double,logic

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...

passing a workbook Name into a For Loop C#

c#,excel,if-statement

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...

Error w/declaration on else statement (C++)

c++,if-statement,declaration

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 <<...

Chance of a conditional occurring in Swift: Xcode

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...

The if statement doesn't work for false in php

php,if-statement

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...

chained if-else not working (C++)

c++,if-statement,chained

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...

Comparing cell contents against string in Excel

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....

Check if VB.net dataset table exists

vb.net,if-statement,dataset

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...

if condition in try process

android,if-statement,try-catch

To test for null you should not use globalnidn.equals(null) but rather globalnidn==null ...

Hiding #DIV/0! Errors Using IF and COUNTIF in Excel 2010

excel,vba,if-statement

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,...

How to close the process from class code?

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 =...

SQL Syntax error #1064 cursors (mysql)?

mysql,sql,if-statement,stored-procedures,cursor

The END IF of the second IF is missing.

How to break if-else-if using C#

c#,if-statement

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 =...

Using ifelse Within apply

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...

How do I format the logic for 3 conditions and use a previous condition as well?

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...

Why does my nested for-if loops load much slonger when I dont nest this? And can I possibly fix this?

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...

didBeginContact logic OSX swift

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 } ...

jQuery/Javascript get classes of multiple elements to show an element with this class

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(); ...

Rails keeps ignoring an IF statement inside the view

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...

Display only values containing specific word in array

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 ...

[: : integer expression expected

bash,if-statement,integer

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 AND OR statements

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:"...

Javascript % operator in IF statement

javascript,if-statement

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...

Spreadsheet if else sum

excel,if-statement,spreadsheet,calc

something like: if(exact(e4;"bought");i4-f4;if(exact(e4;"sold");f4-i4)) works for you???...

Java equivalent of C#'s 'Enumerable.Any'

java,if-statement

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)...

Time's Tables Quiz (Error)

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 ;...

Have an if statement look ONLY at the first word in a string [duplicate]

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()) ; ...

Complex if clause imbrication

java,if-statement

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:...

Jquery, Javascript click && value

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...

Convert a string to a double for a if clause

android,string,if-statement,double

try this String text = "your string"; // example double value = Double.parseDouble(text); hope it helps ...

Is there a way to shorten my if(word.Contains(“tree”) ||word.Contains(“water”)||word.Contains(“sky”)) [duplicate]

c#,if-statement

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 } ...

Java dice roll with unexpected random number

java,if-statement

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...

Stop Prevent Default in else clause

if-statement,mobile,menu

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'); } }); ...

Replace the following query in sqlite

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 inside for syntax error

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 ...

how does Java handle && inside if statement

java,if-statement

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...

How to add a class to an element that is outside of your onclick element

javascript,jquery,if-statement,onclick

$('a.feature_thumb').click(function(){ $('.' + this.id).addClass('your-class'); }); DEMO...

Javascript if (window.location.href) adding two urls

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....

How to make nested IF statements neater

python,if-statement

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...

second else if stament is NOT working properly

bash,if-statement

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...

SyntaxError: Unexpected token if

javascript,if-statement,token

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...

if compare doesn't work in php

php,if-statement,compare

Can you try like: if (intval($line) == intval($rowActual['pid'])) {...} There may be some unwanted characters in the data while reading from file....

Simple quiz won't wait for an answer

java,if-statement

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...

Preventing the user from entering identical elements(within a malfunctioning try catch)

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...

Combining multiple for loops into one using the OR operator

c++,if-statement,for-loop

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;...

How does this code print odd and even?

c,if-statement,macros,logic

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...

How do I check whether a file or file directory exist in bash?

bash,if-statement

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...

PostgreSQL conditional statement

sql,postgresql,if-statement

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 ...

considering if, else if, else statements when writing code (java)

java,if-statement

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,...

if statement doesnt work as i would expect them in python [duplicate]

python,if-statement

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 program after if statement is not exectuing

python,if-statement

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)....

Swift won't allow me to use `!=`

ios,swift,if-statement,null

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.

Float comparision in C [duplicate]

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.

Exit Sub within nested if statements not working

excel,vba,if-statement

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...

SAS else if clause confusion

if-statement,sas

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...

Getting my program to go back to the “top” (if statement) (Java)

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...

Matched data inside select supposed to selected by default

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> ...

pulling and comparing dates in excel

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...

Stopping condition on a recursive function - Haskell

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...

Problems with control flow structures using strings

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...

Switching between date format in a for loop; Python

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 ...

IF-Statement Combination with mb_strlen doesn't work [closed]

php,if-statement

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 ){...

xslt condition output one by one

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> ...

What is the best way to rewrite this repeated if statement?

php,if-statement

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> ...

Reduce the if-statement itself

c#,if-statement

You can use All: if(Enumerable.Range(0, 9).All(c => excel_getValue("A" + (i + c)) == "")) { } ...

If statement for search field in Rails

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?.

Check if string contains non-alphanumeric except underscore

c#,if-statement,alphanumeric

You just need to extend the logic within the All: if (!(key.All(c => char.IsLetterOrDigit(c) || c=='_'))) ...

R: recursive function to give groups of consecutive numbers

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 =...

PHP - If a string or variable begins with a vowel

php,if-statement

$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)...

If/else problems in python

python,if-statement

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...

How do I get my logic in this Java program to make my loop work?

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...

Excel IF AND OR condition together

excel,if-statement,condition

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") ...

using if statements in tableau on a contains function

if-statement,contains,tableau

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 =...

How to use AND operator for comparison in javascript?

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...

Get actual path from path with wildcard

powershell,if-statement

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 } ...