conditional-statements

Why would you use an assignment in a condition?

狂风中的少年 提交于 2019-11-26 10:32:17
In many languages assignments are legal in conditions. I never understood the reason behind this. Why would you write: if (var1 = var2) { ... } instead of: var1 = var2; if (var1) { ... } It's more useful for loops than if statements. while( var = GetNext() ) { ...do something with var } Which would otherwise have to be written var = GetNext(); while( var ) { ...do something var = GetNext(); } I find it most useful in chains of actions which often involve error detection, etc. if ((rc = first_check(arg1, arg2)) != 0) { report error based on rc } else if ((rc = second_check(arg2, arg3)) != 0) {

Can you use if/else conditions in CSS?

徘徊边缘 提交于 2019-11-26 08:49:31
问题 I would like to use conditions in my CSS. The idea is that I have a variable that I replace when the site is run to generate the right style-sheet. I want it so that according to this variable the style-sheet changes! It looks like: [if {var} eq 2 ] background-position : 150px 8px; [else] background-position : 4px 8px; Can this be done? How do you do this? 回答1: Not in the traditional sense, but you can use classes for this, if you have access to the HTML. Consider this: <p class="normal">Text

How can I check if a string only contains letters in Python?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 06:37:07
问题 I\'m trying to check if a string only contains letters, not digits or symbols. For example: >>> only_letters(\"hello\") True >>> only_letters(\"he7lo\") False 回答1: Simple: if string.isalpha(): print("It's all letters") str.isalpha() is only true if all characters in the string are letters: Return true if all characters in the string are alphabetic and there is at least one character, false otherwise. Demo: >>> 'hello'.isalpha() True >>> '42hello'.isalpha() False >>> 'hel lo'.isalpha() False

x86_64 - Assembly - loop conditions and out of order

好久不见. 提交于 2019-11-26 05:56:51
问题 I am not asking for a benchmark. ( If that was the case, I would have done it myself. ) My question: I tend to avoid the indirect/index addressing modes for convenience. As a replacement, I often use immediate, absolute or register addressing. The code: ; %esi has the array address. Say we iterate a doubleword (4bytes) array. ; %ecx is the array elements count (0x98767) myloop: ... ;do whatever with %esi add $4, %esi dec %ecx jnz 0x98767; Here, we have a serialized combo(dec and jnz) which

Difference between JA and JG in assembly

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 05:36:13
问题 Can you please tell me the difference between JUMP IF ABOVE AND JUMP IF GREATER in Assembly language? when do i use each of them? do they give me different results? 回答1: As Intel's manual explains, JG interprets the flags as though the comparison was signed, and JA interprets the flags as though the comparison was unsigned (of course if the operation that set the flags was not a comparison or subtraction, that may not make sense). So yes, they're different. To be precise, ja jumps if CF = 0

Can you use 2 or more OR conditions in an if statement?

社会主义新天地 提交于 2019-11-26 04:52:37
问题 I tried to test this myself before asking on the forum but my simple code to test this didn\'t seem to work. #include <iostream> using namespace std; int main() { cout << \"Enter int: \"; int number; cin >> number; if (number==1||2||3) { cout << \"Your number was 1, 2, or 3.\" << endl; } else if (number==4||5||6) { cout << \"Your number was 4, 5, or 6.\" << endl; } else { cout << \"Your number was above 6.\" << endl; } return 0; } It always returns the first condition. My question is, is it

MySQL select with CONCAT condition

*爱你&永不变心* 提交于 2019-11-26 04:42:45
问题 I\'m trying to compile this in my mind.. i have a table with firstname and lastname fields and i have a string like \"Bob Jones\" or \"Bob Michael Jones\" and several others. the thing is, i have for example Bob in firstname, and Michael Jones in lastname so i\'m trying to SELECT neededfield, CONCAT(firstname, \' \', lastname) as firstlast FROM users WHERE firstlast = \"Bob Michael Jones\" but it says unknown column \"firstlast\".. can anyone help please ? 回答1: The aliases you give are for

javascript: using a condition in switch case

血红的双手。 提交于 2019-11-26 04:40:01
问题 Sorry for that dumb question. How can I use a condition for a case in the javascript switch-case language element? Like in the example below, a case should match when the variable liCount is <=5 and >0; however, my code does not work: switch (liCount) { case 0: setLayoutState(\'start\'); var api = $(\'#UploadList\').data(\'jsp\'); api.reinitialise(); break; case (liCount<=5 && liCount>0): setLayoutState(\'upload1Row\'); var api = $(\'#UploadList\').data(\'jsp\'); api.reinitialise(); break;

Wix Installer : Setting component condition property when doing a MSIEXEC admin install at command line

拥有回忆 提交于 2019-11-26 04:02:10
问题 We have three types/flavours of our product, but only one MSI written in WiX. When we build the installer we pass in the flavour via a defined constant: Call MSBUILD.bat ..\\MSIs\\CoreProduct\\OurProduct.sln /p:DefineConstants=\"FLAVOUR=%_Flavour%\" and the constant is setup in Visual Studio, under Build -> Define preprocessor variables as FLAVOUR=50. The build process, passes in values 50, 200 or LITE as the flavour. In the WiX code we have loads of conditions on our components that tell it

Check if year is leap year in javascript [duplicate]

早过忘川 提交于 2019-11-26 03:57:14
问题 This question already has answers here : javascript to find leap year (9 answers) Closed last year . function leapYear(year){ var result; year = parseInt(document.getElementById(\"isYear\").value); if (years/400){ result = true } else if(years/100){ result = false } else if(years/4){ result= true } else{ result= false } return result } This is what I have so far (the entry is on a from thus stored in \"isYear\"), I basically followed this here, so using what I already have, how can I check if