Questions tagged [if-statement]

An "if" statement is a flow control structure in most programming languages that branches execution flow depending on a binary condition, generally evaluated at runtime. If statements are also commonly also called conditionals. When using this tag please also include an appropriate language tag, such as e.g. "java" if your question is language-specific.

Filter by
Sorted by
Tagged with
-3 votes
1 answer
64 views

Is it possible in c++ in an 'if' statement to compare 1 string with 2 others like with numbers? [closed]

if (string1 == string2 && string3) { cout << "Text: "; } else { cout << "string4"; } I have tried different variations of it, i'm not quite sure if this is ...
Szabolcs Sápi's user avatar
-3 votes
0 answers
24 views

Why only the first option of my if/else statements if printing? [closed]

I'm using a json file to take data from courses and put it in a select element. The javascript takes the json data and puts the correct information into the select element. I then want to select one ...
Adavis's user avatar
  • 15
0 votes
0 answers
11 views

Only the author of the comment can delete and edit?

I´m trying to create an if statement using django so only the one who wrote the comment can access the delete and edit icons. I tried different statements and I don´t understand why it won´t work. I ...
jlindeloef's user avatar
-1 votes
0 answers
15 views

How do I make the reminder alarm only if the user was detected?

I have this project of an automatic pill dispenser. I'm using an IR sensor to detect if the user took the pill or not yet. The pill gets dispensed at a certain time, if the user didn't take the pill ...
Karim Ghaly's user avatar
-5 votes
0 answers
34 views

I am trying to make a code tester but some fixes need to be done [closed]

I am trying to make a code tester but some fixes need to be done.. I am trying to make a code tester but some fixes need to be done..I have identified a few issues with the code tester that need to be ...
M.Srikanth Karthikeyan's user avatar
-1 votes
1 answer
57 views

Declaring a boolean variable inside a if statement [closed]

I declared a variable called length inside a if statement which checks for length of a string. After that I tried to check length's value but got an error stating it is "not associated with any ...
Bharat's user avatar
  • 1
0 votes
0 answers
48 views

How to slove 'length = 3' in coercion to 'logical(1)' in paleofire package

I am using paleofire package v1.2.4 under R version 4.3 0, which is available from https://github.com/oblarquez/paleofire. Although the package hasn't been updated for a while, I want to use its inner ...
Yuwan's user avatar
  • 1
-1 votes
1 answer
64 views

how to know how many if condition is true in your code c++

i have writen a code with if conditions and eevery time the user get an answer right he get 1+ and at the end i wanted to show him his final score but i dont know how to know how many if conditions ...
omar benadada's user avatar
-1 votes
0 answers
51 views

which one is safer in this case?

with the guard: DispatchQueue.main.async { [self] in guard let response else { guard let responseError else { AppStateStore.shared.alertMessage = serverError?....
Mahmoud_omrani's user avatar
0 votes
2 answers
67 views

Difficulty with Rock Paper Scissors game

I'm making a code in Java that is a rock-paper-scissors game. In particular, I am trying to make it so that the randomized outputs, aka if a user loses, wins, or ties, it is counted into the score. ...
zuha's user avatar
  • 3
-1 votes
0 answers
21 views

The code only prints the first if statement [duplicate]

name = input("What is your name?") talent = input("What is your main talent? ") dream = input("What is your dream? ") height = input("What is your height?(short or ...
Shiv Dixit's user avatar
0 votes
0 answers
31 views

Excel function using "Vlookup or IF or Match"

I need to compare two databases. I have extracted the data from both DBs. Database A has hundreds of Employee Names(A2) and their Employee IDs (C2) Sheet Called 'Hold' Database B has a few dozen ...
Chris Casey's user avatar
-1 votes
0 answers
28 views

Java not branching based on two equal values [duplicate]

My program has the following code. It asks the user to enter the ID of one recipe, which it prints out, and then compares it against a list of recipes. When the user enters an ID identical to one in ...
edPC's user avatar
  • 1
-5 votes
0 answers
51 views

If statement but I need to search the message for it first [closed]

I am trying to ONLY forward messages where the marketman is below 900k and the caller consistency is above 20% and I am trying to translate the k in to thousands m to millions and b to billions. A ...
Egirlneedhelppls's user avatar
0 votes
1 answer
42 views

How do i check a list (T) of tuples up against a list (H), followed by extracting +-5 of these tuples in list which corresponds with element in H)?

I haven't done much list/tuple checking and i wanted to try it. I want to extract elements from list, compare lists containing tuples and add some statement to them. count1 = 100 theCounter = range(...
Ben's user avatar
  • 1
-1 votes
1 answer
48 views

setting different conditions on multiple columns of a data frame in one go

I need to write a condition saying if 9 columns of a big data frame include either of the followings: "6%t" (as the first three characters in each row), or NA, or "", then save ...
Rara's user avatar
  • 113
0 votes
1 answer
47 views

how can I decrease the number of variables?

public class Mavenproject8 { public static void main(String[] args) { int num=100+(int)(Math.random()*900); Scanner blue=new Scanner(System.in); System.out.println("enter 3 numbers ...
winstar345's user avatar
0 votes
0 answers
50 views

Exception "if" so that the button is displayed only when the data is completed

I need help adding an "if" exception to my code so that the "button" is displayed on the page only when the data in "$customtab.description" is completed in the module. ...
Rafal's user avatar
  • 25
-4 votes
0 answers
83 views

How to use dictionaries instead of huge chain of "if" statement in Python [closed]

I've found such block of code as a solution to create a unit conversion calculator instead of using a huge chain of "if" statements, but I cannot find a solution to how and where I can ...
Luke Perkins's user avatar
-4 votes
2 answers
88 views

Which condition print both if and else block same time in java? [closed]

public class Example { public static void main(String[] args) { if (condition) { System.out.printf("If block executed"); } else { System.out....
Akoram M's user avatar
2 votes
2 answers
77 views

What is a good way to use Regex effectively for file names?

I have some Files on my Computer. Examples : [Group] Name Year ' [Class2B] Hans 2011 Group_Name_Year ' Class2B_Hans_2011' Name-Year-Theme 'Hans-2011-Wikipedia' These are word files from my students. ...
Matt Gregorin's user avatar
0 votes
0 answers
49 views

Derive conditions for each variable assignment from pseudocode

I have some pseudocode that is in the form: patch a: if b == "foo1" then a = "No" if c == "foo2" then if d == "foo3" || d == "foo4&...
mohammed ali's user avatar
0 votes
1 answer
78 views

How can I efficiently check if a key exists in a dictionary? [duplicate]

I'm knee-deep in a Python project and could use some guidance. I have a dictionary, and I need to check whether a specific key exists in it. I've done a bit of poking around in the Python ...
Mohd Azfar Khan's user avatar
0 votes
0 answers
6 views

PIL image contact sheet syntax error in if statement

Trying to add images to a contact sheet but getting a syntax error in the following line, 7 from the bottom (in italics with stars around it), please can someone help? # facecrops is a list of the PIL ...
ajeking 's user avatar
0 votes
0 answers
22 views

AHK GUI IF statement needed

Created an AHK Calculator GUI that when you select copy it will copy all information to paste. I would like to edit the script to not copy a section if that section is blank. GUI is set up for 3 ...
CuppaJoe's user avatar
0 votes
0 answers
15 views

How To Display Certain Text In A Shared Div According To The Different Pages The Javascript Is On?

I am new here. And I am working on a webcomic layout script. I want to show the page's info (Chapter #, Page #, Chapter Title, etc.) on the designated pages. An example is-- If the visitor is on page ...
KayleneA's user avatar
-1 votes
0 answers
28 views

Adding 52 when year is equal to 2023 [duplicate]

I would like to add 52 to my "week_num" variable when observations in the "year" variable are equal to "2023". My current strategy is below, however it is not working ...
Levi M's user avatar
  • 21
0 votes
1 answer
22 views

vue3 / quasar: Inline condition (if/else) not working for scope.set for popup edit

I am using a q-popup-edit in vue3/quasar where I want to allow the submit on keyup.enter only if a given condition is true. I am confused why this does not set the scope (nothing happens): @keyup....
Benjamin's user avatar
-2 votes
1 answer
47 views

Unexplained Segmentation Fault in simple loop, works with two if statements but not three?

There is a lot going on so i put some arrows pointing towards the if statements in the add function that are breaking the code. When I test the code with only 2/3 of the if statements that I need to ...
PapaPumpkin's user avatar
-4 votes
1 answer
84 views

I'm a new programmer and I'm trying to get this code to work, but I can't seem to get the variables x, y and z to be bound

price_apple = 1.00 price_pear = 1.50 apple_stock = 50 pear_stock = 30 totalstock = apple_stock + pear_stock while totalstock != 0: totalstock = apple_stock + pear_stock if totalstock == 0: ...
Jack's user avatar
  • 11
-4 votes
0 answers
37 views

I want for Microsoft SQL, a if else statement [closed]

I have a table with an item column, here I save certain text, I then work with this text and do calculations with different parts of the text. In every text there is a name, such as R, T, G and I have ...
GenshPro's user avatar
-4 votes
1 answer
38 views

What is the purpose of using "Null" as a condition into IF statements? [closed]

I'd like to create a timer using JavaScript but I had this problem when I wanted to understand the code: What is the purpose of writing this code in if statements : let [seconds, minutes, hours] = [0, ...
失敗者此人's user avatar
0 votes
0 answers
30 views

working on a create your own adventure with python. But I'm trapped getting invalid options [closed]

This is the code I'm currently: pasting the code it completely messes up the spacing. But it does work. The problem with what I have rather than accept the valid input I'm putting, it immediately ...
spandextampon's user avatar
-2 votes
0 answers
27 views

if else block within for loop [duplicate]

let arr1 = ["ravi", "tom", "lois"]; let question = prompt("Enter your name"); let answer = arr1.indexOf(question); for (let i = 0; i < arr1.length; i++) { ...
vp177's user avatar
  • 1
-2 votes
1 answer
84 views

Tighten up an IF/Elif/Else exercise [duplicate]

I'm writing a short exercise based around IF/ELIF/ELSE. You can tell I'm a complete newbie. I'm somewhat proud of what I've figured out so far on my own, but there is something I'm struggling with. I'...
Hueski's user avatar
  • 1
0 votes
1 answer
53 views

Is there a way to display: none; all but one element using if statement?

Trying to hide all but one product card so that the one displayed product card can be turned into a carousel to display the hidden product cards when carousel buttons are clicked. Product cards will ...
TiredOfBeingBroke's user avatar
0 votes
2 answers
30 views

TypeError: Cannot read properties of undefined - using ref property of imported component in v-if (vue3)

I am trying to integrate a audio player into a vue3 site. The component I aim to use is this one Link. I trying to create a play/pause button that I can place anywhere on my site (separately from the ...
Benjamin's user avatar
0 votes
1 answer
17 views

Plane ticket booking software and array

dear programmers in particular, I have a question about how to add arrays to a plane ticket reservation program, and I am experiencing some problems because I am a beginner. My first problem is that I ...
user22841596's user avatar
-4 votes
0 answers
35 views

Python Program for Calculating Factorials with Error Handling" or "Recursive Python Factorial Function with Error Resolution" [closed]

The error in the provided Python program is that there's no base case to handle negative numbers. If a negative number is passed to the factorial function, it will result in an infinite recursion, ...
Anirudh Kumar singh's user avatar
1 vote
1 answer
34 views

Writing a query with multiple outputs In Libre office base

I have two tables, one of which refers to parents, one of which refers to children. Parent_ID Parent_Name Parent_Contact And Child_ID Child_Name Childs_parent The Childs_Parent field is identical ...
Bemberlina's user avatar
1 vote
3 answers
67 views

C: how to convert this code for an use with array?

Consider I'm still a newbie with C, so I made a lot of confusion. This code works fine int error(int a, int b, int c) { if (( a < 0 ) || (a > 255)) { printf("Number is over 255 or ...
elbarna's user avatar
  • 625
0 votes
1 answer
18 views

Salesforce Apex If-Statement with OR-Logic

I like to write and If-Statement in Apex Code with the following logic: The Variable myVariableString can be blank, empty, ValueA, ValueB, ValueC or, and here I asume, because the Variable gets its ...
ioSven's user avatar
  • 15
1 vote
0 answers
35 views

Exclusive conditions and execution of branches [duplicate]

Suppose you have 4 conditions exclusive from each other and you want to execute every branch if the corresponding condition is met.How do you do this?
Root Groves's user avatar
-3 votes
0 answers
36 views

i want to create an array that stores user input [duplicate]

[As you can see I get an error in line 30, I don't get what's wrong since it only prints the array with corresponds to variable i that increments each loop. I already get the concept of loop and if ...
Klxnt's user avatar
  • 1
0 votes
0 answers
40 views

how can i make my string comparison work?

I know this is a super noob question. I'm expecting to give a random string to player 2 and compare it to the player... I can see player2 being reassigned , however the if statement doesn't seem to ...
sghost's user avatar
  • 1
0 votes
0 answers
20 views

How to deal with multiple landing pages with Selenium/Python?

I am wiriting a script to e.g. sign into emails. I am coming up against an issue where I am not sure the best way to deal with multiple scenarios. For example one website may have a couple of possible ...
GR123's user avatar
  • 27
-1 votes
0 answers
32 views

If statements and for loops in JavaScript [duplicate]

I don't know where I am going wrong in this problem please can somebody help? It's on a learn coding site and won't let me pass to the next question until I get it right Jim plans to buy new pack of ...
Beth Arnold's user avatar
0 votes
1 answer
30 views

Finding Grade Entry Date based on change in Grade Value

I have the following Dataset Date ID Grade Grade Previous Grade New 2005-05-08 0034 30 29 30 2006-10-23 0034 31 30 31 2006-09-10 0034 31 31 31 2020-12-08 0034 32 31 32 2003-01-22 0023 25 25 25 ...
mustafghan's user avatar
-3 votes
1 answer
57 views

Problem write nested if python statement (can't run second elif and else in the end if input wrong just show the first elif) [closed]

i get problem when i try make nested if in python please solve my problem inputuser = input("Enter Username :") inputpass = input("Enter Password :") user = ("john") ...
ZxBays's user avatar
  • 1
0 votes
0 answers
25 views

Is it possible (in PHP) to create an IF statement that checks to see if many variables (ie. $var1, $var2, etc) have a value? [duplicate]

Is it possible (in PHP) to create an IF statement that checks to see if many variables (ie. $var1, $var2, etc.) have a value, such as "Heavy" and if one of those variables do, then do xyz... ...
Sebastian John's user avatar

1
2 3 4 5
1239