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
2
votes
1 answer

multiple VBA if statements triggering different event

Sorry i think this is pretty basic but I was wondering if somebody could tell me why only 1 of these IF statements seem to run. The 3rd IF statement for the "CASH" option works but the other 2 unfortunately don't. Sub HideUnhide_Discount() If…
Peter Mogford
  • 478
  • 1
  • 4
  • 15
2
votes
1 answer

Python Exceptions for when an if statement fails

I have a simple exception class: class Error(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return self.msg I also have an if statement which I want to throw different exceptions from depending on…
BrandonM
  • 390
  • 4
  • 12
2
votes
3 answers

Use while loop to avoid deeply nested if statements in java

Hi I have written a little function like public void foo(MyClassA paraA) { if (paraA == null) return; MyClassB paraB = doSomeStuff(paraA); if (paraB == null) return; MyClassC paraC = doMoreStuff(paraB); if (paraC == null)…
user1589188
  • 5,316
  • 17
  • 67
  • 130
2
votes
1 answer

smarty nested if condition is not working properly?

I have written my code like this, {if $quant eq 1} {if $val neq ""} .....//some code {else} .....//some code {/if} {else if $quant eq 0} .....//some code {/if} but the above nested smarty if condition is not working as…
Manikandan
  • 1,784
  • 7
  • 21
  • 30
2
votes
1 answer

Nested If statement Excel - checking if value exists

I have a spreadsheet with multiple row with varying data in the collumns eg: Student NO Book1 Book 2 Book 3 Book 4 Book 5 X 12 Y 13 12 23 23 32 What I want to do is a…
KingJohnno
  • 602
  • 2
  • 12
  • 31
1
vote
4 answers

Better alternative to many nested if statements in this context?

if (task1 != null) //Do something with task1 else { if (task2 != null) //Do something with task2 else { if (task3 != null) //Do something with task3 else { if (task4 !=…
SkonJeet
  • 4,827
  • 4
  • 23
  • 32
1
vote
4 answers

nested if in haskell

//edit 5 when the i use only these 2 lines index :: [String] -> [String] -> Bool index a b = and [x `elem` a |x <- b] it works fine!!!! eg: index ["asd","asdd","dew"] ["asdd","asdad"] False But when i use the entire code mentioned below empty…
pier
  • 503
  • 3
  • 14
  • 29
1
vote
2 answers

removing nesting of if statements

I have a piece of code, which I am not sure how to refactor.. It is not very readable and I would like to make it readable. Here is a the problem There are two columns in database which can be either NULL, 0 or have a value each. On the web page…
tryurbest
  • 1,419
  • 1
  • 12
  • 22
1
vote
3 answers

is it possible to print only one statement in this nested if code?-Java

Our professor asked us to create a code that prints what grade you should be getting for a particular score, in a nested if code in Java import java.util.Scanner; public class nestedif { public static void main(String []args){ Scanner…
1
vote
1 answer

Check if uid numbers in /etc/passwd are in a certain range and not already used, with nested ifs

I am trying to check the uid's that are already used and in within a range from 1000 to 60000, with nested if conditions but only the range condition works. Also it prints the $hpass content. Any ideas how to improve the code? Thanks in advance for…
1
vote
1 answer

Filter in Google Sheets not working within IF statement mismatched range sizes

I am receiving the following error: FILTER has mismatched range sizes. Expected row count: 1759. column count: 1. Actual row count: 1, column count: 1. The function in question is: =IF(F2="", "Please enter a year", IF(F4="", …
1
vote
2 answers

Replacing if/if with if/and returns false (Google Sheets / Excel)

I need cells on Sheet_2 to return a specific value from Sheet_1 (column K) on the condition that the values in other particular cells on Sheet_2 match with cell values on Sheet_1. I already have a pre-made formula that works, but I wanted to change…
1
vote
2 answers

Showing Top 5 Clients at a dashboard

I want to build a dashboard where I can select a year and a application and want to have the top 5 clients shown up. I build a example Sheet ofr…
1
vote
1 answer

google sheets if and statements not workings

=IF(and('Form Responses 5'!BA:BA="Service/install",if('Form Responses 5'!Y:Y="V723")),sum('Form Responses 5'!Z:Z),"") I want it so if ba:ba="service.install" then add z:z if ba:ba="sending" then add z:z bonus if I could get it to be also included if…
1
vote
2 answers

Filter Data in Googlesheets

I have to face some problem about my Googlesheets Data. I want to filter my googlesheets data between two dates and also filter more conditions at the same time in same sheets. Below are given some sample…