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
-1
votes
4 answers

else statement within nested if statements. How does this code know which else statement to execute?

I get the nested if loops (same as using && operator), but how does this code here know which conditions to execute with no conditions and just back to back else statements? One of them is within the nested if statements. I can tell that's…
dannymac
  • 517
  • 5
  • 14
-1
votes
1 answer

Java nested if statements

I'm using an instantiable class and nested if statements in Java. When I run this it always outputs 500 even when the input is more than 5. Summer: less than 5 people is 500, more than 5 people is 400 Autumn: less than 5 is 700, more than 5 is…
ncirl.eva
  • 15
  • 5
-1
votes
2 answers

Searching an entire column within MS Excel and returning a "Yes" or "No" in a separate cell

it pours!), I am trying to write a statement in MS Excel 2013 that does the following: If any cell within Column Y (except for cell Y1 - as it is a heading) contains a date, then output "Yes" in cell Z2. Else output "No" in cell Z2
-1
votes
1 answer

Nesting if checks with C++

Maybe my code is sloppy, but for some reason it just passes through all the nested If checks without pausing to check for an answer beyond the first one. Also the first If check goes on to the nested If for True no matter what even if I give it a…
Illyduss
  • 161
  • 1
  • 3
  • 11
-1
votes
1 answer

IF Statement help, Triple nested

I'm looking to return a value of 0 if cell C47 has a value at or below 0, but I keep getting a return of the negative value of cell E9. All the other calculations in the formula work great. I can't figure out what I'm doing wrong. I'm new to nested…
-1
votes
1 answer

C - Switch Statement vs If Statement for Employee Pay?

I am working on an employee pay program in C and I am trying to find a better way of organizing the code for calculating the pay for the Hourly Worker. I want to use a switch statement, instead of a boatload of if statements. I was just wondering…
-1
votes
3 answers

Nested if, not exiting - create a function to call functions

I have the following code to validate form data. I have created functions to validate various groups, and then have an if isset statement to check if these functions return true. I have tried many different ways to get this to work. The problem I am…
user3956566
-1
votes
8 answers

Java Nested If condition

I suddenly got a strange doubt.. I want to know whether if(a && b) { } is same as if(a) { if(b) { } } or not.. Both the cases giving me the same result. But, I'm still not feeling comfort to use the first method in my project. Any helps??
Gugan
  • 1,625
  • 2
  • 27
  • 65
-1
votes
7 answers

Nested if conditions

I'm facing huge problems with nested if conditions in our core java application An abstract of code is as below....we can have nearly 20 nested if conditions can you tell me how to optimize this piece of code ? what is a better way of avoiding this…
Deepak
  • 2,094
  • 8
  • 35
  • 48
-2
votes
1 answer

How do I get my t-sql code to check for a condition then stop? not check the next condition. Return should be only one result

Pseudo: If condition is true, return results and don't look for next condition. If condition is false, then check for the next condition. etc ...I have like 6 of these to check in a hierarchy order. Case check every condition and so instead of…
Tami
  • 17
  • 6
-2
votes
5 answers

Can someone tell me what's wrong with this code? It's beginner level

I am completely new to python, i'm learning it online through a course and got stuck in an exercise. I can't figure out the problem at all, i feel like my solution to the exercise is ok but whenever i choose the option of adding cheese to my "S"…
Zo.A
  • 9
  • 3
-2
votes
2 answers

python program for finding greater number among of 4 numbers, using nested if

WHAT IS WRONG IN THIS CODE? MY PC SHOWS NO OUTPUT WHEN C and D ARE LARGER NUMBERS? a=int(input("ent a no.")) b=int(input("ent a no.")) c=int(input("ent a no.")) d=int(input("ent a no.")) if a>b: if a>c: if a>d: print(" a is…
-2
votes
2 answers

Why won't my C code complie when thier is no error shown?

Ok, so i was working on a code that would calauate the penalties for intoxicated driving having 3-90 days of peanlity for # of peanlites commited and the fine from $200-500. But i wanted to ask why is my code not compliing below? Any explanations on…
-2
votes
2 answers

Showing wrong output

It is a problem from hackerrank. https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem?h_l=interview&isFullScreen=false&playlist_slugs%5B%5D%5B%5D%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D%5B%5D%5B%5D=warmup #include…
-2
votes
4 answers

Write a program that will take three integers as input and will print the second largest number

I have tried this program to take 3 integers and print the 2nd largest number: #include int main() { int a,b,c,max2; printf("Enter 3 integers: "); scanf("%d%d%d",&a,&b,&c); max2=a; if(a>b){ max2=b; …
Maria
  • 67
  • 1
  • 3
  • 7