Questions tagged [if-statement]

12602 questions
1

votes
1

answer
1.6k

Views

Python- How to make an if statement between x and y? [duplicate]

This question already has an answer here: How do I check whether an int is between the two numbers? 7 answers I've recently been breaching out to Python, as C++ is fun and all, but python seems kinda cool. I want to make Python do something as long as the input is between a certain number range....
Nate Dukes
1

votes
2

answer
49

Views

If user skips rows to input a numeric value, force user to type in data in the following available row

I have a sheet and the user input Starts in A7 and calculations are inserted with a macro to B7 all the way through I. I got all that worked out but what i need is: the user is going down typing in data in Column A, lets say they input data Starting from A7, through A11, then skip A12 and type int...
1

votes
3

answer
45

Views

The program is skipping the if in my if else statement PHP

Here is my php code: Here is the html form that sends the information: USD/Canadian Money Conversion Site Starting Amount: 1 10 20 Conversion type: USD to Canadian Canadian to USD Conversion Rate: Step: 1 2 3 4 For some reason the php does not recognize the value of whichWay if the user selects US...
Caleb
0

votes
1

answer
11

Views

Replacing an if statement's condition character with a variable

This is probably an easy one. In R, can I replace an if condition character (such as >) with a character and execute the if statement with it? For example, if the if statement is: ifelse(1 < 2, 'T', 'F') But I'm getting the > condition character through a variable: cc
dan
1

votes
1

answer
48

Views

Mark all cells which do not include two given words

I am writing a code which should mark in a range, in red, all cells which do not include the words 'bel' and 'hsa'. Sub Check() Range('c2:c49').Select For Each cell In Selection If (cell.Value 'bel' Or cell.Value 'hsa') Then cell.Interior.Color = RGB(255, 0, 0) End If Next cell End Sub It works if...
Marco D.
1

votes
2

answer
42

Views

Writing to a file inside if statement not working in Perl

I've looked around here a bit and found similar questions but not exactly. If there is one, I apologize and please point me to it. I have the following code. I'm trying to create a csv file of simply an ID pulled from a filename and the filename itself. This is the ENTIRE script. use strict; use war...
Reverend Bubbles
1

votes
1

answer
21

Views

R - If statement function to set value of new column

I have 2 columns pos and neg, each with a integer value. I would like to create a new column score, with each element of this column given a value of: 1 if pos > neg 0 if pos = neg -1 if pos < neg What would be the best way to do this? I am new to creating functions in R, so any help or direction i...
leftail
1

votes
1

answer
41

Views

fish: if error: `[: Missing argument at index 2`

I am a first-time Fish user and curently I try to convert my Bash prompt (PS1) to fish_prompt, which I save to ~/.config/fish/functions/fish_prompt.fish. This is a similar problem as this, however, the solution does not work for me. I tried to remove the [], use test, however, I have no idea how to...
tukusejssirs
1

votes
3

answer
44

Views

How to make the code in my function return editted dataframes

I am attempting to use ifelse statements in R to add a specific prefix to my dataframes. I have two issues with my code at the moment. 1) When I try to wrap this in a function it does not return the edited dataframes. 2) the no = parameter of the ifelse statement I have put in repeats itself, how...
Krutik
1

votes
2

answer
81

Views

Angular's ngIf showing else template before evaluating condition

I'm checking if there are any elements in array before showing them. If there aren't, a 'not available' message should be displayed. Class: public lists = []; public isLoading: boolean = false; ngOnInit() { this.getLists() } getLists() { this.isLoading = true; this.list.getShoppingLists().subscrib...
shAkur
1

votes
2

answer
35

Views

How to check whether a file exists, outside a Makefile rule?

This is a pseudo code: if .gitignore exists GITIGNORE_PATH := .gitignore else GITIGNORE_PATH := ../.gitignore fi all: do_build... I tried to search this, but they always show how to do this inside rules, as in: $(UBIN)/%: @if [ -f '[email protected]' ]; then \ $(CC) $(CFLAGS) -o '[email protected]' $(OBJS) -L $(ORAHOME) $(ORAL...
user
0

votes
1

answer
22

Views

Program to find vowels, If statements not assigning correct values

I have a simple program to find the vowels in a string. The for loop is supposed to iterate through the string and see if the char matches any of the vowels using and if else block but the output is just 100 As. I tried making them all just ifs but that gave all Us. #include int main() { const in...
C.Deighton
0

votes
0

answer
7

Views

`dplyr::if_else()` compared to base R `ifelse()` - why rbindlist error?

This code block below utilizing dplyr::if_else() works without issue and produces the flextable shown. library(tidyverse) library(flextable) # utilizing dplyr if_else df1 % mutate(col3 = if_else(apply(.[, 1:2], 1, sum) > 10 & .[, 2] > 5, 'True', 'False')) df1 %>% flextable() %>% theme_zebra() I fi...
Jason Hunter
-2

votes
1

answer
24

Views

How can I make an if-statement based on what has randomly been printed?

so I am creating a type of game that will involve dices. What I plan on doing is to have different things happening depending on what the player throws, it will be a 2 player game. What I want to do is make the computer randomly generate 2 of the 6 possible dice sides. After that has been printed,...
Emma Eriksson
1

votes
1

answer
13

Views

How to compare string value by index and column and apply AND OR logic within dataframe?

I have a dataframe that looks like this: col1 0 ofcourse 1 I love the service The dataframe could also have this value for row 1: col1 0 ofcourse 1 I hate the service I want to compare the value of the strings by row and column and be able to check for one of two values in row1. I want to creat...
RustyShackleford
0

votes
0

answer
9

Views

Why are all possible integers “true” in the range of long int inside if-statement in C++, but 0 is not?

Basically, how does an if-statement analize whether an integer is true or false? These two simple lines print out 'Hello', with a positive integer 764: int a=764; if(a){ cout
Betelgeuse
1

votes
3

answer
170

Views

semicolons for empty lines after if statements [closed]

I got this open source JS project and trying to browse the code I found this several times: if(evt.success){ ; evt.success(response.result); } An empty line ending with a ';' Does this mean something ? or it's just a typing error ?
Alucard
1

votes
2

answer
48

Views

The typeof operator is not operating as expected

I am attempting to check if a particular javascript object exists. var success = function(data) { var x= 0; var numOfCards = data.length; for (x=0;x
Jordan
1

votes
4

answer
2.5k

Views

How to use ELSE statement in .bat file that has multiple IF statements? [duplicate]

This question is an exact duplicate of: How to use an If Statement in .bat file to run one of Multiple options [duplicate] I'm writing a Windows batch file to enable, disable or make manual a Windows Service. How would you use an ELSE statement if you have multiple IF options? For example: if /I '%c...
Thelps
0

votes
0

answer
14

Views

R check if column exists and if it does check something about it

Hi I want to check if a column in a data.frame exists, and only if it does check another conditions. I know I can use a nested if statement as I have in the example. This is normally for checking inputs to functions. This is a working example which gives me the output I want, I just was wondering i...
user2738526
1

votes
3

answer
219

Views

R - if_else assign na value

I have a dataframe in R. My goal is to create a new column with if_else statement. If the value in a row is equal to the string 'company', then the value of this new column will be the value from data column. Otherwise, I'd like to assign to if NA value. I don't know how to achieve that, my code bel...
Sklenicka
1

votes
4

answer
65

Views

Objective C: A cleaner way to check if a string isn't empty before creating and assigning a string to a dictionary key?

I am creating an NSMutableDictionary and assigning an NSString (test and test1) to a parameter key. NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; if (test.length) { dictionary[@'test'] = test; } if (test1.length) { dictionary[@'test1'] = test1; } This method does work. Howeve...
Curt Rand
1

votes
4

answer
87

Views

Python: Why do my 'if' statements' evaluate numbers incorrectly? [closed]

The code is as follows: from random import * numStars = int(input('Number of stars: ').strip()) planetTypeDict = {'O':0, 'B':0, 'A':0, 'F':0, 'G':0, 'K':0, 'M':0} for star in range (numStars): planetTypeChanceNum = uniform (0, 100) if planetTypeChanceNum < 76.45: planetType = 'M' planetTypeDict['M'...
dominic thorpe
1

votes
3

answer
59

Views

Is there a way to let biggest value on X (out of X, Y, Z) decide value on V in R?

I have a dataset (ft.mutate.topics) with five variables (four numeric are ft_technical, ft_performative, ft_procedural and ft_moral). The fifth is 'topic_lab' and I would like for it to take on the name (as a character) related to the variable with the highest value of the four other. The below prod...
ABG
1

votes
2

answer
50

Views

Evaluate multiple values to a condition

I have a bunch of variables that I need to verify whether they are within a determined range. Below is a quick example to demonstrate what I want to achieve. a=1 b=3 c=5 if 0
Malyk
1

votes
4

answer
48

Views

Python - If Statement With input() Not Functioning Inside def() Function

Everything in the code runs properly except def a() and def b() have and if statements that examine and input function though when I run the code it will lead to 'good for you' being printed no matter the input. For instance if I type False or Whatever into the code which should lead to different re...
Mr. Tenderoni
1

votes
2

answer
40

Views

SQL If condition is true Update table

i am trying to write a one line sql statement that can check for a certain condition and if the condition is met I need to update a table with a new value. below is what I want to do, I just cant find out how to accomplish this. any help would be greatly appreciated. if (select * from table where fi...
J_Newby
1

votes
1

answer
52

Views

Python stop increment a list in certain condition

I am trying to implement a simple left rotation in a list. Please review the following code:` def left_rotation(n,d,arr): temp = arr for i in range(n): print(temp[i]) # here is the problem if (i-d < 0): arr[i+n-d] = temp[i] else: arr[i-d] = temp[i] return arr print(left_rotation(5, 4,[1,2,3,4,5]))...
jmamath
1

votes
2

answer
47

Views

Checking the value in the dataframe in R

The following are my r code. I am trying to check whether the true value a = 10 is included or in the dataframe. If its included in the dataframe, then I need to compute the length of that data frame otherwise I want to assign the length 0 . Assume the value I am checking is 10 k1 = c(1,2,3,5,6) k2...
score324
1

votes
4

answer
67

Views

How to make an “if( variable1 < X more or less Y)”?

I'm currently creating a little game, and I need to create a condition. In pseudo-code, it would look like something like this : if (a < x with x included in [b -10; b +10]) { then c = 2 } Is there an easy way to do this ? I know it may not be really clear, so ask me further details if you didn't...
Theoph
1

votes
3

answer
54

Views

How to simplify compound negated logic

Lets say I have array of boolean values B[], or I am figuring out true/false using function. How can I simplify this code, it there are many values (maybe tens of them)? Here is pseudocode: if(!B[0]){ doTask1; } if(!B[0] && !B[1]){ doTask1; doTask2; } if(!B[0] && !B[1] && !B[2]){ doTask1; doTask2; d...
victory
1

votes
3

answer
143

Views

Multiple conditional statements for list comprehension Python

I have a list with elements that I want to do operations on with 2 conditions. One condition is to multiply a norm function by -1 if the element is negative or leaving the norm function positive if the element is positive. The list of values looks like this: print(values) -97476.70633454417 -93170.3...
HelloToEarth
1

votes
2

answer
49

Views

Force ifelse() statement to work only for first occurrence in R [duplicate]

This question already has an answer here: How to find first element of a group that fulfill a condition 3 answers My ifelse statement: df$baseline
Theresa Uyen Le
1

votes
2

answer
26

Views

Error when using if_else applied to times and dates

Below's a sample of my dataset, where I have GPS positions (Latitude and Longitude) and the date and time they were registered: > head(datanet) Date & Time [Local] Latitude Longitude 1: 18/06/2018 03:01 -2.434901 34.85359 2: 18/06/2018 03:06 -2.434598 34.85387 3: 18/06/2018 03:08 -2.4347...
juansalix
1

votes
3

answer
45

Views

is there a way to find which condition in an if statement failed in powershell

I have multiple checks in an if condition and if any one of them fails status should be failed. For this what I have now is multiple if statements comparing each value to something so that script can notify what exactly failed. Is there a way that I can put these condition in an and criteria in if s...
rahulruns
1

votes
2

answer
65

Views

I am new to ruby language , and trying to create a text adventure game , i want to include two strings

I want the user to type anything, but it should include two strings like 'look' and 'right', if both are included in the sentence then the program will go to the next line. I am new to ruby, just getting myself familiar with the language. I have tried && and || but it doesnt work puts ' in which di...
sherryretro
1

votes
3

answer
34

Views

Using ifelse() with an interval as conditional expression in R

My dataset looks like this: > head(GLM_df) # A tibble: 6 x 9 # Groups: hour [6] hour Feeding Foraging Standing ID Area Feeding_Foraging Feeding_Standing Standing_Foraging 1 0 3.5 23.3 1 41361 Seronera 26.8 4.5 24.3 2 1 2.71...
juansalix
1

votes
3

answer
1.3k

Views

Allowing decimal in numbers only field with JavaScript

I have a function which I use to limit form inputs to numbers only, or number and decimals depending on the field. Allowing decimals and numbers is easy enough, but I am trying to take it a step further and allow only one decimal, while also making sure that decimal is not the first character in th...
ubiquibacon
1

votes
5

answer
2.1k

Views

PHP functions and if/else statements

I am trying to write a script that includes if/else statements and functions. some background $parts first character should have the letter 'N' $desc is suppose to be at least one character long $price needs to be positive (0 or higher) if all three of theses requirements are met then it should say...
TBP
1

votes
2

answer
22

Views

If statement confuse me

I have this code here for a slider and I don't understand what if statement does. In my head are 2 options: if(current===sliderImages.length -1 MEANS current=== 1 if(current===sliderImages.length - 1 MEANS if the current is === 2(length of array) then take away 1 HERE IS ALL CODE let sliderImages =...
DConstantin

View additional questions