Questions tagged [if-case]

The if–then construct (sometimes called if–then–else) is common across many programming languages. Although the syntax varies quite a bit from language to language, the basic structure (in pseudocode form) looks like this: If (boolean condition) Then (consequent) Else (alternative) End If

11 questions
3
votes
1 answer

if-case pattern matching - Variable binding in a condition requires an initializer

I'm working through Big Nerd Ranch's Swift Programming book (2nd edition), and in the chapter on the Switch statement, there's a small section on in-cases and how to use them. When describing how to implement if-cases with multiple conditions, this…
enharmonics
  • 259
  • 3
  • 9
3
votes
1 answer

complementery of an if case

How would you write this: if case .SomeEnum(3) = enumType where myInt == 3 { //I don't need this case } else { //This is the case I need } I know I could use guard: guard case .SomeEnum(3) = enumType where myInt == 3 else { //This is the…
Daniel
  • 20,420
  • 10
  • 92
  • 149
3
votes
1 answer

Is it possible to use 'if-case' in place of a switch that has a coma delimited list as a case?

Swift 2 introduced if-case which is supposed to be a more terse way of expressing a switch that only has a few cases. I'm wondering if there is a way of expressing a switch statement with a comma delimited list as an if-case. let (a,b) =…
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
1
vote
2 answers

Using mutate, if_else, and rowSums to create a new var based on condition

I have a data frame which is in long format. I have multiple cities. Each of the cities has information for each month and information also for each code (this code goes from 100 up to 1,000). My dataframe looks like…
1
vote
0 answers

Alternative for If conditions and replacing it with inheritance

So my problem is that you have a lot of if conditions to be checked and inside that if condition you have multiple lines of code. I want to eliminate it and use inheritance instead. For every if statement I will be using a separate class to handle…
Akila Randil
  • 205
  • 1
  • 10
0
votes
2 answers

Is there a nested for loop aproach to inside parameters in a fcase() in R?

My code is like this: fcase(V2009 == 9L & V3006 == 2L, V1032, V2009 == 10L & V3006 == 3L, V1032, V2009 == 11L & V3006 == 4L, V1032, V2009 == 12L & V3006 == 5L, V1032, V2009 == 13L & V3006 == 6L, V1032, …
0
votes
4 answers

Improving SQL query for covid-project

I was wondering if any of you could help me to improve this query SELECT IF(cases.country_region LIKE '%Korea%', 'South Korea', IF(upper(cases.country_region) = 'IRAN (ISLAMIC REPUBLIC OF)', 'Iran', IF(upper(cases.country_region) =…
0
votes
0 answers

Expected ',' joining parts of a multi- clause condition in a Swift "If Case"

let age = 25 if case 18...35 = age where age >= 21 { print ("In Cool Demographic and of drinking age") } In Swift, when I type the code above, it says right before in "where", there's a little red line under the "w" and it…
0
votes
2 answers

Bash scripting - if cases $? > 0

Sorry for possible spam, I'm finishing RHEL Security Hardening/Auditing script, where I want an overall result in the end. For example, # PermitEmptyPasswords grep -E '^\s*PermitEmptyPasswords\s+no\s*' /etc/ssh/sshd_config &> /dev/null if [ $? = 0…
kd.maxi
  • 60
  • 1
  • 1
  • 10
0
votes
1 answer

select case, according to find text

I want to update a sheet with new data about every 15 minutes. the code I'm looking for is something like: case data is not exist in the sheet "do something" case else "do somthing else" The code i wrote is: Dim LastRow1 As Long With…
-1
votes
1 answer

compare Value of cookie returns "false" every time

I got a function named getCookie(x) which returns the value of the cookie with name x. When i check with console.log(getCookie(foo)); it returns the correct term of either solved or an empty string if the cookies doesnt exist. Foo is a variable! For…