What is If statement: Definition and 22 Discussions

In computer science, conditionals (that is, conditional statements, conditional expressions and conditional constructs,) are programming language commands for handling decisions. Specifically, conditionals perform different computations or actions depending on whether a programmer-defined boolean condition evaluates to true or false. In terms of control flow, the decision is always achieved by selectively altering the control flow based on some condition (apart from the case of branch predication).
Although dynamic dispatch is not usually classified as a conditional construct, it is another way to select between alternatives at runtime.

View More On Wikipedia.org
  1. M

    If statement & PopUp window in React

    Hey! :smile: I have a checkbox with radio button and I want that a popup message is shown if we have selected the second option. I tried to do that with if statement but it doesn't work. How do we write the if statement in React? Isn't it 'condition ? true : false' ? Do we not check if the...
  2. M

    Python Is this if statement being evaluated?

    Line 7 in the code below seems to remove an element from stack, but why is this happening since it's just checking a condition? I'm pretty shocked I don't have to remove the previous char from stack myself. def isValid(s): stack = [] dict = {"]":"[", "}":"{", ")":"("} for char in s...
  3. L

    Comp Sci C++, float and double having different effects on an if statement?

    So I used this statement, if (call_time > 0 && call_time <= 6.59) where the variable was declared as float. What is strange is that it didn't execute for call_time = 6.59, but for some other values, like if (call_time > 0 && call_time <= 2.59) the end value of the range does not cause any...
  4. astroman707

    What's wrong with my if-else statements in Python 3?

    Goal: I'm trying to allow the user to input varying spellings for certain auto services, and still have my code work properly. My goal was to use the if-else statements to ensure that if the user misspelled a service, the code could correct the error by changing the variable assignment to the...
  5. M

    If statement for Monte Carlo integration

    Hello, I am writing a program on Fortran to calculate the integral of sin^4(x) between x = 0 and x = π/2. I believe I know how to write the correct code, but I am unsure what the if statement should be for whether or not a point is inside the desired area. Any thoughts? Thanks.
  6. P

    Mathematica How to Use If Statements Inside a Do Loop with Complex Numbers?

    I have a Do loop running which, for some values will become complex, and I want to make it so for these situations, we take the negative root and for others the positive root. In this scenario, I've simplified what I actually have and chose to look at the case where I need it to take the...
  7. FallArk

    C/C++ What does the modulus operator mean in a C++ if statement?

    I have run into an if statement as shown below: if (randoms[(x * 3) + y] % 2) I don't really understand what this means. Thank you for helping!
  8. sk1105

    Nested IF statements or multiple conditions?

    Currently in my C++ program I have something like if (A){ do thing 1; } if (A && B){ do things 1 and 2; } if (A && B && C){ do things 1 and 2 and 3; } and so on. Unfortunately this has to be done for a very large sample and it takes quite a long time. I was just wondering if it's more...
  9. L

    Fortran Using Integer Expressions in an If Statement: Help Needed!

    Hi, so I'm trying to use the following if statement: if (sum(i,j) <=1.0 ) then sidash=(si)*(Death) else if (1 <= sum(i,j) <= 2) then sidash=(si)*((sqrt(2.0)+1.0)*(2.0-sum(i,j))*(Death)+(sum(i,j)-1.0)*(Survive)) else if (sum(i,j)<=3 .and. sum(i,j)=>2) then...
  10. W

    Java Java While Loop and If statement

    I am reading an input file that has blank lines. x reads character by character. x is equal to a new line so it goes into the while loop but skips the if x == '\n'. It's suppose to go inside the if statement but it doesn't. I tried debugging the code and printed out to double check x is holding...
  11. P

    Why is my if statement executing when its false

    quick question, not sure why i can't work this out. in the following code my if statement executes, but as far as i can see i have set the boolean so that it shouldnt. public void actionPerformed(ActionEvent e) { boolean contains = false...
  12. D

    Nested if statement within a do-while loop

    I don't understand why this would work, shouldn't it be "while(x)" because we don't want to repeat the loop? int main(void) { int x=0; do { printf("Enter an amount:\n"); scanf("%lf", &amount); if (amount < 100) x=1; else printf("Invalid"); }while(!x); return 0; }
  13. H

    (dis)prove an if and only if statement of a Cauchy sequence and and interval.

    Homework Statement A sequence (Xn) is Cauchy if and only if, for every ε>0, there exists an open interval length ε that contains all except for finitely many terms of (Xn). Homework Equations The Cauchy Definition is: A sequence X = (xn) of real numbers is said to be a Cauchy sequence...
  14. T

    Verilog if statement always activating

    So i am writing a Verilog program for a combination lock. I am using a state machine format to write it. I have commented out everything and just isolated one if statement as you can see. No matter what i put in the if statements the code within it (next_state = Inuse;) activates. The only way i...
  15. S

    MATLAB If statement in Matlab involving time variable

    Im Having trouble writing an if statement with the time variable of the ode45 function. I don't know if i need to create a new variable, which is not what i want, but just to create and if statement with the t variable from ODEs. Hope someone knows how to solve this problem Thank you
  16. N

    Comp Sci Java help (how to not to use if statement)

    Java help ! (how to not to use if statement) My teacher asked the user for an integer and converted it into a number in base N, where N was a value between 2 and 9, inclusive. Expand this program to allow values of N between 2 and 36, inclusive, where digits representing the numbers 10, 11...
  17. Saladsamurai

    Nested If statement Simple but what Am I missing?

    I am learning VBA for Excel and Am just wondering what is wrong with the logic in this statement? Note that at the present moment, Time < 0.5 , but my program is outputting "Good Evening" Sub Better_Nested_If() Dim Msg As String If Time < 0.5 Then Msg = "Mornin'" Else...
  18. M

    Can I Use an IF Statement for Regression in Excel?

    Regression in Excel I want to make an regression of some data, but I only want to use some of the data. The data I want use is where Vacant = 1. Is this possible in excel? I have tried to use the if-function but the regression does not like "false" More info I want to make a...
  19. fluidistic

    Fortran Fortran 90 very basic question : else if statement

    Hi there, I've tried all I could in order to complete a very simple and basic program that finds the roots of any quadratic binomial. You have to enter the coefficients a, b and c and it would find the roots. I could do that, but a problem occurred if I typed a=0. Of course if a=0 the...
  20. L

    True or false/correct if statement is false help

    N is the same as Kg/m/s^2. False...K.g/M/s^2.? It is easier to sweep with a brown if your hand is further up on the handle. true? a screw with fewer threads is easier to use than a screw of the same size with more threads.-true? water at 4^0C is lighter than at 4.1^0C. True? ice can...
  21. Math Is Hard

    PHP Form data passed to php if statement

    Howdy, tonight I was playing around with trying to pass a value from a form field and use it for an "if" statement in php. the html: <HTML> <HEAD> <TITLE>Form Test</TITLE> </HEAD> <BODY> <H1>Form Test</H1> <form name="input" action="myscript.php" method="get"> Enter a 1 or a 2...
  22. Math Is Hard

    C program - trouble with IF statement

    I feel silly asking this but I can't get my "If" statement to work correctly. This should print "a is NOT equal to b" but it prints "a is equal to b". Any help? Thanks! #include <stdio.h> int main(void) { int a = 10; int b = 15; if(a == b) printf("a is equal...
Back
Top