if-statement

Batch nested If statement error with not defined variables

亡梦爱人 提交于 2019-12-24 13:58:08
问题 I have a problem with a simple batch script. See: SET TEST= IF NOT DEFINED TEST ( SET "TEST=1" ) ELSE ( IF %TEST% LSS 1 ( SET "TEST=1") ) Here the if in the else branch failes, because the variable TEST ist not defined. But the else branch even shouldn't been executed if the variable TEST isn't defined!? What is here the problem? (I knew, that this code would work, if I leave the else and write it under the if statement, but then this code get's executed every time.) How to solve this problem

PHP output only one value in for each

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 13:05:23
问题 I'm having trouble with output in for each function in PHP (actually don't know how to set the code to do what I need). I'd like to output some text if every item in foreach is equal to some value. If I put foreach($items as $item) { if($item == 0){ echo "true"; } } I will get true for every item and I need to output true only if all items are equal to some value. Thanks! 回答1: This peice of code work for most type of variables. See how it works in inline comment. $count=0; // variable to

What happens when “if” statement is ended with a semi colon [duplicate]

China☆狼群 提交于 2019-12-24 13:04:58
问题 This question already has answers here : Semicolon at end of 'if' statement (18 answers) Closed 4 years ago . In a program, I needed an if statement and by mistake, I put semicolon at the end of the statement. However, there were neither compile-time error nor run-time error. I tried to figure out what this code means but hopeless. if (i == 10); { System.out.println("It is here"); break; } If you enlighten me on this topic, that will be appreciated. 回答1: The if statement has nothing to do

Error: unexpected '}' in “}” if…print()…else…print() [duplicate]

天大地大妈咪最大 提交于 2019-12-24 12:43:30
问题 This question already has answers here : if/else constructs inside and outside functions (2 answers) Closed 5 years ago . I WAS GIVEN ANSWER: THE if's closing BRACKET should be BEFORE ELSE not ABOVE. This error had already been discussed here: Error: unexpected '}' in " }" and https://stackoverflow.com/questions/15303559/error-unexpected-in But they do not help me. I run the code: i <- 21 if(i==22){ print(c("xxx")) } else{ print(c("yyy")) } And get an error else{ Error: unexpected 'else' in

Is there any reason Python would skip a line?

无人久伴 提交于 2019-12-24 11:49:18
问题 I'm just a few months into learning python and I'm trying to write a program which will help to test characteristics of a password. I'm so close to getting what I need but one line seems like it keeps getting skipped and I can't figure out why... Here's the code: def main(): print("Create a password. Password must follow these rules:") print(" - password must be at least 8 characters long") print(" - password must have one uppercase AND lowercase letter") print(" - password must have at least

Simple raw_input and conditions

孤街醉人 提交于 2019-12-24 11:44:07
问题 I created the simple code: name = raw_input("Hi. What's your name? \nType name: ") age = raw_input("How old are you " + name + "? \nType age: ") if age >= 21 print "Margaritas for everyone!!!" else: print "NO alcohol for you, young one!!!" raw_input("\nPress enter to exit.") It works great until I get to the 'if' statement... it tells me that I am using invalid syntax. I am trying to learn how to use Python, and have messed around with the code quite a bit, but I can't figure out what I did

Is it possible to use IF(cond1 AND cond2,result,else result) in MySQL?

江枫思渺然 提交于 2019-12-24 11:37:20
问题 I want to do update query if the consecutive 5 column have 0 value. My first idea is: UPDATE `table_name` SET `count` = IF(`col1`=0.00 AND `col2`=0.00 AND `col3`=0.00 AND `col4`=0.00 AND `col5`=0.00, count+1, count) But I think using AND in IF condition isn't work. Any idea? Thanks before 回答1: Using AND in an IF is perfectly valid, but as Grijesh suggets, using the condition in the WHERE clause is the usual way to do it. Your query though shouldn't give any errors. 回答2: I think you need this,

How to correctly shorten an if-statement in C++?

╄→гoц情女王★ 提交于 2019-12-24 11:35:42
问题 Okay, I have an if sentence in which I compare a specific value multiple times. I bet there is a shorter way to do this: if(letter == "%" || letter == "+" || letter == "-" || letter == "!") I tried writing it as: if(letter == "%" || "+" || "-" || "!") But it works incorrectly. 回答1: Something like this might work: string s("%+-!"); if (s.find(letter) != string::npos) { ... } 回答2: That's as short as it can. You could rewrite it though, with some help from Boost it could be if( boost::is_any_of(

Parse json and choose items\keys upon condition

 ̄綄美尐妖づ 提交于 2019-12-24 11:28:04
问题 I'm trying to parse a json file that I get from a certain REST API. The json has a few arrays, and I'd like to choose a specific item from an array based on the value of another item. for example: [ { "item1": true, "item2": "value" }, { "item1": false, "item2": "value" } ] I'd like to check if item1 is true, and only then, i want to get the value from item2. how would I handle it? I've tried to use a json parser named underscore which is great, but I cant get to the final result. thanks 回答1:

OR and AND combinations inside if-statement

萝らか妹 提交于 2019-12-24 10:59:33
问题 I have this selector: $('ul:not(.sub-menu) > li, ul.sub-menu > li:last-child').not(':has(ul.sub-menu)'); which gets these elements: Every direct li descendant whose parent is not .sub-menu (unless it's the last, cf. 2.) Every last li element of an ul.sub-menu Exclude all li 's that are parent to a ul.sub-menu Now, I want to use this in an if-statement, which is inside a hover-function. In other words, it's got to be relative to that list item instead of being the list item. Something like