Questions tagged [if-statement]

1

votes
2

answer
210

Views

Last iteration on For loop with If condition with twig

So this is only an example of what I'm trying to achieve. I'm looping through all items and print only those, who starts with F and separate them with comma.So in the end, the loop will made, for example 15 iterations, but will print only 5.I'm trying to catch the last one that will be printed, so I...
Vladimir-Manov
3

votes
2

answer
20

Views

Find elements in a list of which all elements in another list are factors, using a list comprehension

I have a list of numbers from which I have extracted common factors of all these numbers. For example, from list b = [16, 32, 96], I have produced list_of_common_factors = [1, 8, 16, 2, 4]. I have another list of integers, a and I wish to extract the numbers from list_of_common_factors of which all...
kashveyron
-2

votes
1

answer
22

Views

Which one is better in terms of space/time complexity?

in terms of space/time complexity, which is better? if (!(N % 2 == 0) || N % 2 == 0 && (N >= 6 && N = 2 && N 20)) { System.out.println("Not Weird"); } // OR if (!(N % 2 == 0)) { System.out.println("Weird"); } else { if (N >= 2 && N = 6 && N 20) { System.out.println("Not Weird"); } } I'm try...
Lean Junio
1

votes
2

answer
95

Views

Alternative way of implementing nested if statement

I am trying to refactor this code I have below that uses several nested if statements to check if two list contains the same items. List CarList = CarService.findCarByConfigtype(pageName); for (int i = 0; i < CarList.size(); i++) { System.out.println(CarRestApiController.data().getModel()); if (Car...
user3061322
1

votes
2

answer
34

Views

Should be a matching if Statement (Textarea & Div)

I want to click on an item in the removeFood div and have it match to the item in the text area newFoodName1 $(".removeFood").click(function() { var removedFood = ($(this).children('.dailyItem').text()) $(this).text('') var selectedFood = $("#newFoodName1").text(); console.log(removedFoo...
AndrewLeonardi
1

votes
5

answer
58

Views

Shorten Code by accessing Dictionary with if

I have the following code Dictionary changesDictionary = new Dictionary(); if (changesDictionary.ContainsKey("field1")) { resultObject.field1 = changesDictionary["field1"]; } if (changesDictionary.ContainsKey("field2")) { resultObject.field2 = changesDictionary["field2"]; } if (changesDictionary.Con...
Dr. Snail
-2

votes
2

answer
21

Views

Html/ Javascript login

I am in the middle of making a one use login using javascript to create if else statements to see if the input from my html form matches the correct username and login. i haven't been able to find out what the problem is but something is keeping it from loading the link i have it set to open when yo...
Jacob Kiss
0

votes
0

answer
3

Views

WinForms, checkbox if statement execution

I'm trying to execute a class when the checkbox is checked but that wasn't working so I now am trying to execute within the checkbox1. here's what I have so far. I have tried using a class and doing something like AutoInjector.cs AutoInjector AI = new AutoInjector(); then I tried using it like this....
Kynan
6

votes
5

answer
282

Views

How to code these conditional statements in more elegant & scalable manner

In my software, I need to decide the version of a feature based on 2 parameters. Eg. Render version 1 -> if (param1 && param2) == true; Render version 2 -> if (!param1 && !param2) == true; Render version 3 -> if only param1 == true; Render version 4 -> if only param2 == true; So, to meet this requi...
Ryan Gusto
-2

votes
3

answer
25

Views

If statements in loop (python)

I have 20 sectors and want to print my points per sector. With a bunch of if statements it looks like this: if sector == 0: print(1) if sector == 1: print(2) if sector == 2: print(3) ... if sector == 19: print(20) How do I make this shorter and put it in a loop?
helpme
0

votes
1

answer
39

Views

Angular2: Why does 'else' not get executed in subscribe function?

I'm trying to verify that the response email field matches the email to the user which is logged-in. When I navigate to an URL (detail/:id) which was set up by another user and doesn't belong to the currently logged-in user, Angular should display an error message. So far so good. But in my case, th...
dmnktoe
1

votes
0

answer
6

Views

R ifelse return value of another vector via index

I cant get my head around this problem regarding ifelse: say I have two vectors: x
gorg
0

votes
4

answer
21

Views

if condition on node js

I'm Getting confused I tried to have to have a two condition, in the first code I'm getting true answer seems the answer should be false. var a = 'route 3'; if(a === 'route 1' || 'route 2'){ console.log('true') }else{ console.log('false') } on the second code, I have two conditions and the first co...
Jomar Tinga
2

votes
3

answer
66

Views

What is the difference between MultiWayIf and classic guards?

What does MultiWayIf extension offer that cannot be done using | guards and vice versa? For instance, one can write same function as f x | x == 0 = -1 | otherwise = x or f x = if | x == 0 -> -1 | otherwise -> x I don't see any difference between these two examples beside syntactic sugar used. Are t...
radrow
0

votes
0

answer
14

Views

R - ifelse function with date and time

this is my first question here and I'm pretty new with R and programming so probably it will be an obvious question. I have a data.frame with column "DateTime", column "Night_Starts" and column "Night_Ends", all of them in the format "YYYY-MM-DD hh:mm:ss". All of them are factors. Looks like this:...
Lisa Tedeschi
-2

votes
0

answer
13

Views

Is there any way I could improve this piece of PHP code?

Is there a way I could make this code simpler or smaller? i.e. in one line, instead of an if statement inside an if statement? Just to clarify, this works perfect, but I feel like there should be something way easier than this. if (isset($_GET["update"])) { if ($_GET["update"] == "false") { echo ' F...
Jesper
0

votes
1

answer
28

Views

Logic not working - matching values with ages in a list

I am trying to match particular values (val_A) to ages I have in a list (val_B) in csv format. I am using the below Python code but it's never meeting the first two criteria. The last two elif and the else statements are working, and almost always the else criteria is applied. def age_convert(val_A...
user9645302
-1

votes
3

answer
29

Views

Why does this while loop execute but produce the incorrect answer?

Cobalt-60, a radioactive form of cobalt used in cancer therapy, decays over a period of time. Each year, 12% of the amount present at the beginning of the year will have decayed. If a container of cobalt-60 initially contains 10 grams, determine the amount remaining after five years. The code that I...
jo T
0

votes
0

answer
11

Views

Variable Not Defined After Conditions

This is supposed to be a passcode generator program in Python 3. import string from random import * print("Type Yes or No For The Following Questions:") letters = raw_input("Do you want letters in your passcode?" ) if raw_input == 'Yes': chars1 = string.ascii_letters elif raw_input == 'No': chars1...
Jason Walia
1

votes
3

answer
43

Views

Why does this while loop not execute under the if statement?

I am new to python and stackoverflow. I am trying to learn by working on small projects The project is on population: In 2014 China’s population was about 1.37 billion and growing at the rate of .51% per year. In 2014 India’s population was about 1.26 billion and growing at the rate of 1.35% per...
user9991165
1

votes
2

answer
40

Views

Combining an ifelse statement with shift data.table function in R

I am trying to work out how I would combine an ifelse statement with the shift function in data.table. My data looks like this: DF df CHR SNP BP KBdist locus 1 rs2494631 2399149 NA 1 1 rs4648637 2401364 2215 NA 1 rs2494627 2402499 1135 NA 1 rs11122119 6768...
Lynsey
1

votes
1

answer
20

Views

OR condition with EJS?

Both of these statements work: They have a High School Degree They have an Associates Degree This statement does NOT work They have either a High school or Associates Degree why does the OR function not work?
AndrewLeonardi
1

votes
2

answer
66

Views

How to use if else condition inside nested map function in react-native?

I am making a react-native app that has a custom view like a grid view. All the cells of the view have same size except one. I want to give condition for the cell to have double the size from others. I am making the view through an array using map function. Map function is not taking if statement. H...
Neha
1

votes
1

answer
30

Views

If statement formula breaking VBA loop code

I have a spreadsheet to track jobs that go through the workshop, on a separate sheet i have a macro that will only show live jobs. To determine which jobs to display, on the main sheet i have used an if statement formula like below: =IF(NW3="complete","0","1") so if a job is listed as complete it wi...
BilboBaggins90
0

votes
2

answer
50

Views

How to use Java Optional to convert a complex if condition

Consider the following class Class RequestBodyResource { private RequestVariable1 att1; private String att2; private String att3; } I have a method that should return false in 2 conditions If all the 3 attributes of the RequestBodyResource Object is null/empty If more than one attribute is not null...
vivekp
1

votes
3

answer
1.7k

Views

In bash, How do I test if a word is not in a list?

Good day everybody, I want to make an if conditional with the following aim: have two files, the script check a word of file1 (locate in variable $word2test) if exits in file2 (each word locate in variable $wordINlist) do nothing | if the word is not in file2, print it to stdout My first approach is...
-3

votes
2

answer
25

Views

Random Number Generation in C# errors out

So i am trying to generate a random number and if the number is 3 or 8 i what something to happen , it this case to add 1 to one of the 2 integers keep in mind i really am only going off a book in C# and some knowledge in VB int Number1 = 0; int Number12 = 0; string text; string text2; Exexs: Rando...
Kernel
1

votes
3

answer
66

Views

If Statement with Empty _Get

I am busy learning PHP. However doing a small website with PHP where I control the Variables passed, I am stuck at a If statement issue. Every internal page link I have passes a variable to control the content I pull from a database. even links from other internal pages to my Index.php page. The thi...
Cavemanharris
1

votes
2

answer
836

Views

Ruby if statement - how to avoid multiple elsif statements including not

I am creating a piece of functionality to auto generate descriptions based on attributes I have on properties (in a Rails app). I have created a series of service classes to handle this - here is class RoomDescriptionGeneratorInternetTV < RoomDescriptionGeneratorBase def generate if internet? && c...
Ben Hawker
1

votes
1

answer
437

Views

Is exiting a function with an empty return statement good/bad practice?

I've seen many examples and this is getting me more than curious The two examples are the following : Having return;at the end of a void function, this is flat out ridiculous. Using return;in the middle of a function to break out of it. I don't like it. The following example might clarify the second...
Gil Sand
1

votes
4

answer
134

Views

Application where user inputs month number 1-12 and http post returns month name isn't working

I have an application that asks the user to input a number 1-12 in a form field. Upon hitting a submit button they should be returned to the http post which tells them the corresponding month. EXAMPLE: if the user inputs '9' the http post SHOULD read "the month you chose is 'September' As of now, t...
HerbalChaos420
0

votes
1

answer
33

Views

Make SQL query select only one of the WHERE conditions

I am trying to run an SQL query in PHP that is supposed to return one row based on the following two fields: first_shown_date last_shown_date I am trying to select the one row based on the following conditions: last_shown_date = Todays date, if false then: first_shown_date = 0000-00-00, if false the...
K.D
-1

votes
3

answer
42

Views

Trying to loop to beginning of program

I don't know how to get the program to restart if the wrong input is given. I am new to java and don't know how to effectively use if statements or loops. import java.util.Scanner; public class TuitionRates { public static void main(String[] args) { //variables String name = ""; String studentTyp...
Joshua Fleming
-1

votes
0

answer
33

Views

what is proper syntax for this if statement? [on hold]

I’m having a syntax error with an if statement. It was working correctly with a different version, but I’m writing to an output log and I didn’t like how it would output for every file it checked, I want it to only write once if the file exists or not. The first code below is the one that is n...
55thSwiss
1

votes
1

answer
12.8k

Views

COUNTIFS in a spreadsheet while ignoring duplicates in a separate column

I'd like to find how to use the COUNTIFS function in excel to count the rows in a spreadsheet while ignoring duplicate values in a separate column. Here is a sample of the data:       [] I would like to count the number of rows that are "One" on status and "Blue" on category. However, I only w...
Teller
0

votes
0

answer
3

Views

if statement with a search text condition in a tuple

I need to write in erlang an if statement with the condition to search this test "tele/folin-house-s1/SENSOR" in the tuples that I recevie. Below I insert the tuples I'm receiving: {message,, 1,, #{dup => false,retain => true}, #{username => undefined}, ,, {1549,8794,985040}}. {message,, 1,, #{dup =...
Luca Folin
1

votes
2

answer
2.7k

Views

If NOT EXISTS in SQL not function

I put this in the SQL Query editor of SQL Server 2008 and doesn't work: If not EXISTS (Select * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA= 'dbo' AND TABLE_NAME='PK01') CREATE TABLE [dbo].['PK01'] (Articulo varchar(MAX),Referencia varchar(MAX),Lote varchar(MAX),Cantidad Int,Ubicacion varchar(...
panki
1

votes
4

answer
121

Views

Bash How to wrap values of the first line of a csv file with quotations, if they do not exist

The other day I asked how to wrap values of the first line of a csv file with quotations. I was given this reply which worked great. $ cat file.csv word1,word2,word3,word4,word5 12345,12346,12347,12348,12349 To put quotes around the items in the first line only: $ sed '1 { s/^/"/; s/,/","/g; s...
Curious Sam
1

votes
2

answer
2.5k

Views

Apply Python lambda : if condition giving syntax error

This is my data set fake_abalone2 Sex Length Diameter Height Whole Shucked Viscera Shell Rings Weight Weight Weight Weight 0 M 0.455 0.365 0.095 0.5140 0.2245 0.1010 0.1500 15 1 M 0.350 0.265 0.090 0.2255 0.0995 0.0485 0.0700 7 2 F 0.530 0.420...
Sachin
1

votes
1

answer
237

Views

Conditionals in Posix Standards

In these days I spent a lot of time reading various articles and guides about scripting (most of all in bash). One of the first things that came up is that the best thing to do is sticking to POSIX, for portability. Anyway, what I couldn't get straight is the standard way to make a conditional state...
ingroxd

View additional questions