Questions tagged [nested-if]

This tag refers to a code structure in which multiple if-statements are placed in a "nested" form (i.e. one if-statement is contained within another).

Use this tag for questions related to constructing, maintaining, or refactoring nested if-statements.

428 questions
3
votes
4 answers

If statement without curly braces

been looking at this one problem I came across. The question is what does the following snippet return. int main() { int a = 1, b = 2, c = 3, d = 4; int x = a; if (a > b) if (b < c) x = b; else x = c; return(x); } As I…
3
votes
2 answers

How to restructure nested if else statement

Say you have the following table for a monster…
3
votes
1 answer

Make Iferror and Googlefinance print "blank" cell if no value

Is there a way to make this formula print empty cells based on the "F" column having no value? I'm currently getting the cell to return "0" but I want it to be blank as I'm trying to combine this manual input with a supermetric query. The purpose is…
3
votes
1 answer

Fill in blank cells in ={ARRAYFORMULA()}

I have a human-friendly sheet with sparse data: PART | FRUIT --------------- Alpha | | Apples | Pears Beta | | Lemons | Oranges I want to create a second automatically updated machine-friendly sheet, which would have all…
Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
3
votes
4 answers

'else' without previous 'if' error when defining macro with arguments

Consider the C code below. #include #define foo(x) if (x>0) printf("Ouch\n"); int main() { int a = 4; int b = -3; if(a>b) foo(b) ; else printf("Arrg!\n"); printf("thanks\n"); return 0; } When…
Huzo
  • 1,652
  • 1
  • 21
  • 52
3
votes
6 answers

How to group range of numbers into categories of number ranges in Google Sheets

I have a column of the range of body mass index numbers (BMI) that I want to automatically group into categories or buckets in another column. It looks like this: colA colB BMI BMI Grouping 23.11 BMI ≥ 18.5 - 24.9 22.66 BMI ≥ 18.5 -…
Ian Bong
  • 45
  • 1
  • 4
3
votes
1 answer

Design pattern to refactor code with nested if else and switch statements

I have to refactor a bulky existing code. Gone through a lot of similar questions on SO and other sites, still confused. If anyone can put some light or any idea will be of great help. There are 5 drop downs and I need to update the view based upon…
3
votes
3 answers

Performance question on nested if's

is there be any performance effect on "Lines of code - (C)" running inside nested ifs? if (condition_1) { /* Lines of code */ - (A) if (condition_2) { /* Lines of code */ - (B) if (condition_n) { /* Lines of…
user3244
  • 35
  • 1
  • 3
3
votes
3 answers

nested "and/or" if statements

I am working on code which creates a list and then applies both the "or" and "and" conditions to do further action: a= ["john", "carlos", "22", "70"] if (("qjohn" or "carlos") in a) and (("272" or "70") in a): print "true" else: print "not…
Ahsan Naseem
  • 1,046
  • 1
  • 19
  • 38
3
votes
7 answers

Help refactor this messed-up-nested-if of a method

Ok I want some opinions how I can fix this mess of a method! It has WAY to many nested 'if' statements. But realize I have to know exactly where the method fails, currently in each of the respective 'else' clause I am logging the error (the failed…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
3
votes
2 answers

VBA Nested IF statement

I want to show a message box when a specific cell has a particular value in it. I have done this with the following code; If Range("P8") = "Y" Then MsgBox "Message here" End If This is within the Worksheet_Change sub so shows the message…
Jonny Wright
  • 1,119
  • 4
  • 20
  • 38
3
votes
1 answer

VBA: Break Out of Deeply Nested If Statements

Typically when I want to break out of a statement I just set a boolean flag for control flow, but I have a special case with many nested If statements and I'd really like to have a way to break out of several with one simple statement. In Java you…
user1205577
  • 2,388
  • 9
  • 35
  • 47
3
votes
2 answers

Java count coinFlip heads in a row, how to highlight streak event

OK so my code works for the task at hand. the assignment is to flip a Coin object that is instantiated from a separate Coin class (not shown here). I have written the code correctly so as to calculate the maximum streak of consecutive flips…
kinghenry14
  • 1,187
  • 1
  • 11
  • 34
2
votes
1 answer

Google Sheets QUERY with WHERE on multiple columns at the same time

Following this post Google Sheets QUERY with WHERE on multiple columns I build up my formula to select specific values from more columns but when I had a condition data start to be confused and not equal to what I selected. I started from this…
2
votes
2 answers

How to compare two formula (calculated) cells in Google Sheets

I am trying to compare two formula (calculated) cells in Google Sheets but I am getting: Error - Formula parse error. The two cells are: =IF(OR(ISBLANK(E5), ISBLANK(H5)),"", E5-H5) =IF(OR(ISBLANK(E5), ISBLANK(J5)),"", E5-J5) And the cell I am…
blubberbo
  • 4,441
  • 4
  • 23
  • 36
1
2
3
28 29