Most voted "if" questions
The "if" statement is a control structure in many programming languages that alters the execution flow depending on a binary condition - also known as Boolean logic. This tag should be used when the question is related to the use and/or performance of the "if".
Learn more…467 questions
Sort by count of
-
4
votes1
answer619
viewsIs it correct to create a variable within an if?
it is correct to create a variable within an if ? In the code below you create a variable within the if, and avoid using the same filter twice. if($id = filter_input(INPUT_GET, 'id',…
-
4
votes3
answers1915
viewsWhat are [ ] bash for?
I’m starting shell script now, and often, reading other people’s programs, I see the use of [] associated with if. For example: if [condition]; then fi I have often seen the use as follows: if…
-
4
votes3
answers146
viewsPerformance "Where in foreach vs if"
Which case would perform best? var chaves = new list<string>(); foreach(var item in lista) { if(!string.IsNullOrEmpty(item.Chave)) { chaves.Add(item.Chave); } } Or listaValida = lista.Where(x…
-
4
votes5
answers29127
viewsuse if in sql server
I have 3 tables in my database, CUSTOMERS, DISTRIBUTORS and EXPORT and I have a production order table where I take the customer type (Distributor, customer or export) and the ID of each of them.…
-
4
votes1
answer664
viewsAccess local variable outside an if
How to create/modify a variable within a if and be able to access it without having to set it in global mode/scope. I am working on a Lua file similar to this scheme: if verificacao then local…
-
4
votes2
answers207
viewsHow to use If Else correctly
I have the following checkboxes: <input type="checkbox" class="check" id="livros" value="livros"/> <input type="checkbox" class="check" id="folhas" value="folhas"/> <input…
-
4
votes2
answers6030
viewsCompare dates in Python
Good afternoon ! I need to solve the following scenario in python: I have one or more files . txt in a folder, but I want to return only the files that have the modification date according to the…
-
4
votes5
answers3418
viewsCheck the amount of negative elements in a JS array
I am initiating Javascript studies and I come across a question where I need to identify negative elements in an array and return the amount of these numbers. Remembering that there may be empty,…
-
4
votes1
answer402
viewsPython - does not allow assigning value to the variable in if conditional, why?
I did something in Python that is common to do in C and javascript, ie, give a value to a variable when an if condition is met. I’m sure that in Python it’s also possible to program in this way,…
-
3
votes5
answers631
viewsIf Else with functions
It is possible to use a if-else with function "Function();" example: if (a > 1){function Save();} else {function NoSave();} I just need to know if functions are loaded into the head work within…
-
3
votes1
answer618
viewsDoubt about conditional (if) in function
I have a set of 300 and few worksheets in which we have to create a function with 3 arguments: the directory where the worksheets are, the variable that will be analyzed and the number of files that…
-
3
votes1
answer477
viewsIF condition is true but does not execute related code
I have my program that displays a message and in that same message the user must enter a code. I’m trying to validate whether he typed something or not, so I use the code: AlertDialog.Builder alert…
-
3
votes2
answers70
viewsPHP parametric functions
I am new in php and I am creating a comparison of box sizes, and for that I would like to put inside a function more I do not know which parameter to put inside the relatives of the function.…
-
3
votes1
answer2810
viewsHow to use multiple conditions within an if
I’ve tried several ways, grouping with () in all the ways I imagined, creating a variable and calling it in condition etc, but I can find where I’m missing. $(function() {…
-
3
votes1
answer91
viewsJavascript toggle or if/Else on Adobe Edge Animate
I use Adobe Edge Animate for simple animations at work. I couldn’t get one of them to work and I did a trick. Now I want to know how to do it right. I have a button. When clicked, it should play on…
-
3
votes1
answer217
viewsHow to make a denial condition with instanceof, without affecting the order of precedence?
I hope the question does not sound strange, but I can clearly explain what I mean. I know that as far as checks are concerned, it is sometimes necessary to take care of the question of the…
-
3
votes2
answers1148
viewsHow to read what the user typed in a form?
The code is like this: <form method="post" action="pagina.php"/> <?php $c= 1; $neg = 0; while($c <=3){ echo "Digite um numero: <input type='number' name='$num' min='1'/>"; if($num…
-
3
votes1
answer12863
viewsReturn to code start after a C if or switch case
I have a question regarding if. I’m developing a program for the end of college semester and every time I need to use one if and at the end of if, I need you to go back to the beginning of the…
-
3
votes3
answers350
viewsSelecting src from an input using ID in Jquery
if(!$("#src-img[src='']")){ }else{ }; I would like to know what is wrong with this if selection, in which case I want, if a value is set in the src attribute, it to execute if, otherwise Else.…
-
3
votes1
answer1756
viewsError: The condition has length > 1 and only the first element will be used
I am writing a code in the R but it informs the following error: In if ((Bwgmax * (1 - Exp(-K * (Mcisimulate - Xm)))) > WG) { : the condition has length > 1 and only the first element will be…
-
3
votes2
answers282
viewsValidate the return of select PHP
I am making a select and before printing the form on the screen I would like to validate if the select returned lines, as I have tried this in various ways without success. $stmt =…
-
3
votes1
answer96
viewsif only executes Else
Hello guys I have this function ifit collects a variable coming from login.php and does a check to choose between two menus. It just doesn’t matter the result inside the variable $permt he always…
-
3
votes1
answer243
viewsPHP - Why should I put an IF in mysqli_prepare()
In the example in Manual PHP was made use of the if before the execution of the instructions. I know that the if is used for comparisons, what comparison is being made here? Follow the example of…
-
3
votes2
answers165
viewsIf - Datatable condition
I need to compare a value of one of the fields of a DataTable, to fulfil a condition if, but I don’t know how to do it. follow below: public partial class imp_orcamento :…
-
3
votes2
answers106
viewsPerformance of ternary operator
I recently came across an assignment to a boolean variable as follows: bool varTeste = (varEntrada == 100) ? true : false; I know this is the same as the code below: bool varTeste = (varEntrada ==…
-
3
votes3
answers1524
viewsIf with 3 conditions and at least 2 true?
Suppose I have the following if if(a || b || c == true) In this case, just one of the values is true to activate the condition, but I would like the condition to activate only when at least 2 of the…
-
3
votes2
answers1732
viewsWhy does if only work with the return of a method?
Follow my code that contains a boolean method: import java.util.Scanner; public class ativ16 { public static void main(String[] args) { int n, i, v[]; Scanner entrada = new Scanner(System.in); n =…
-
3
votes5
answers1540
viewsCheck that all $_POST was shipped without using too many ifs
Good morning, I have to check that all the form fields, sent as $_POST, were not blank, this until I solved. But I wanted to see a way to not need to use too many if/Elif to check every $_POST index…
-
3
votes2
answers1169
viewsValue-finding function between Javascript variables
I have the following form: <body> <form name="questao1" method="post" onsubmit="sendToDB();"> <br><input type="checkbox" name="Q1[]" value="Enfermagem"…
-
3
votes2
answers2069
viewsDisplay the highest and lowest value between two integers when they are different from each other
I am not able to display the values of smaller and larger. Make an algorithm that reads two numbers and indicates whether they are equal or, if different, shows the largest and smallest in this…
-
3
votes2
answers117
viewsI could not resolve the error: The condition has length > 1 and only the first element will be used
I know there are other questions about this mistake, but since I’m a beginner they didn’t help me solve my specific problem. I am working on the following date.frame: structure(list(Dates =…
-
3
votes1
answer26
viewsI don’t understand an ordination resolution
The teacher asked for the next exercise: "Write a program that receives three scores (integer numbers); sort these scores using if instructions and write the three in ascending order on the screen."…
-
3
votes1
answer65
viewsproblem with Random.radint(1, 6) and if conditional
Friends, I am starting out in programming, so I apologize if it is too banal my question. My guess is that something happens in the if string, because never the winning message is read, the program…
-
3
votes1
answer71
viewsIs there a better way to group "Ors" in Python without having to type the variable all the time?
Example: letra = input('Digite uma letra: ') if(letra == 'a' or letra == 'e' or letra == 'i' or letra == 'o' or letra == 'u'): print('Vogal')…
-
3
votes4
answers1152
viewsJavascript function with Nan error
Hello. I am encountering a problem when executing this formula as the final answer is given as Nan. In a simplified way to explain the code, it works like this: there are two groups of three…
-
3
votes1
answer54
viewsWhat is the cost of an update when it does not find the record?
I’m doing some Sqls in my Delphi program and I came up with this question, what is the cost to the bank engine when a UPDATE does not find the record according to the parameters of WHERE? My…
-
3
votes3
answers183
viewsif and logical connectives
I need to find the fewer number and the second to smallest number of five typed numbers. But this strange fact is happening: #Subtrair o menor numero encontrado do numero digitado dif1 = n1 - menor…
-
3
votes1
answer51
viewsWhat is the difference between the pre-processor directive and the if statement?
In what situation should I use the directive #if? And the reserved word if?
-
3
votes1
answer517
viewsIf chained - how to eliminate?
I’m doing an application where I have the following scenario: I have several rules (business classes) where they all return the client code. These are separate classes that will look for the trial…
-
3
votes2
answers175
viewsDoubt of if He is
Good evening, I was testing this C code of an activity* of my course, works ok if (c<101||c>103), works ok if if (c=101), but if (c=102) if instead of returning me ns=s+(s*0.2), is returning…
-
3
votes1
answer743
viewsAccept uppercase and lowercase character
I’m making a draft just to train the if and the else which will be subject in my next class in college. I want to get there and at least already have a basis of what the teacher will teach. My…
-
3
votes1
answer48
viewsDoubt with If statements in R
In this code I am wanting to record the amount of values of z such that -1 < z < 1 inside x, and z < -1 or z > 1 in w. It rotates the rnorm(100)(that is, it creates 100 observations of a…
-
3
votes1
answer94
viewsIs it possible to improve that part of the code?
I need to improve a part of the code. My problem is it’s too repetitive if and else, the bad news is that I will have more repetitive things on account that are different games. I can improve this…
-
3
votes1
answer82
viewsMake if in an HTML tag to add or not attribute "checked"
I’m developing with the .Net Core Razor and I’m setting a string in my GET and I need that, according to what this string (in the case of "true" or "false"), checkbox whether or not marked. To…
-
3
votes3
answers4717
viewsI need to write a suit functionDeruco, that given a suit, returns a list of strings, one for each card of this suit following the cards of the truco
TIP: The cards include all numbers except cards 8 and 9. The reasoning I had at first was to create several arrays each with the suit name (spades, clubs, diamonds and hearts) and then use the FOR…
-
3
votes2
answers119
viewsHow to use 'Else if' correctly?
I built a function called min which returns the smallest number that is passed in one of its two arguments. When the numbers are equal it returns null. I was able to make the code work as follows:…
-
3
votes1
answer177
viewsWeighted average with final examination
I need read 4 notes with weights of 2, 3, 4 and 1, respectively, for each of these notes and I must show this average accompanied by the message "Media: ". If this average is greater than or equal…
-
3
votes2
answers28
viewsCommand to create multiple columns in a data.frame conditioned to other 2 columns
If I have a date.frame formed by the vectors: V1<-c("A","B","C","D","B") V2<-c("C","D","C","B","B") V3<-c("D","D","C","A","A") V4<-c("C","B","C","A","C") G1<-c("C","C","A","A","B")…
-
2
votes1
answer1143
viewsMake an INNER JOIN using IF
I am doing an INNER JOIN of the Combo Table with the Product Combo Table as shown below... SELECT C.SchoolID, C.ComboID, P.Active, P.Name, P.ProductID FROM sales.Combo AS C INNER JOIN commons.Stock…
-
2
votes3
answers596
viewsConditions in Javascript
I recently discovered that it is possible that it is possible to store the result of a condition (such as a if) in a variable: var x = (1 > 2); // false var y = (2 > 1); // true Check out…