Most voted "condition" questions
Use this tag on questions that have conditional execution as the center of the problem, i.e., that depend on boolean expressions for their execution.
Learn more…150 questions
Sort by count of
-
36
votes4
answers58476
viewsIF, ELSE IF, ELSE or IF IF IF. When to use, what’s the difference?
It’s a very basic question, but it intrigues me a lot. See the code below: var bola = "redonda"; if(bola == "comestivel") return comer(); if(bola == "liquida") return beber(); if(bola == "redonda")…
-
26
votes6
answers12868
viewsWhat’s the difference between Isis and elseif?
I wanted to know the difference between else and elseif in PHP, and when should I use one or the other.
-
24
votes6
answers40933
viewsDoes ternary surgery exist in Python?
I often see several programming languages where a ternary operation is almost always identical. (x % 2 == 0) ? "par" : "impar" However, when I went to try to do this in Python, it was wrong: (x % 2…
-
15
votes4
answers3950
viewsWhen to use ternary condition?
I particularly like the use of ternary condition, but I see many developers saying no, there is even a rule in Checkstyle when validating your code that encourages you not to use. See the example…
condition encoding-style conditional-formattingasked 10 years, 9 months ago Philippe Gioseffi 3,202 -
15
votes3
answers2003
viewsIn PHP the correct is Else if or elseif?
In PHP, the correct is else if or elseif? What’s the difference between them? The language allows writing everything together and separately, and apparently the results are identical…
-
13
votes2
answers262
viewsCheck "in" return change the Python result
It is known that to check whether a particular item does not belong to a list it is sufficient to use the operator in: values = [1, 2, 3, 4, 5] if 9 not in values: print("9 não pertence à lista.")…
-
11
votes1
answer2858
viewsWhen should I use the "?" operator in C?
When I should use the ternary operator ? in C? #include <stdio.h> int main(void) { int valor, resultado; printf("\nValor: "); scanf("%d", &valor); resultado = valor < 10 ? 50 : 0;…
-
10
votes4
answers4295
viewsWay to make a comparison between three variables
I need to make a comparison between three variables in my PHP code. if($a == $b == $c) { return true; } else { return false; } I have a lot of ideas on how to do that, but I want to know the best…
-
10
votes2
answers1147
viewsShould I declare a variable within the "if" or separate condition?
I need to call a function that can return false or a value, and in case it returns the precise value manipulate it. So I made a code similar to the one below: //A função que é chamada é muito mais…
-
9
votes2
answers426
viewsIs there a way to break in If?
I was wondering if there’s some kind of break on IF. My doubt is based on the example below. When the function b() returns false all following comparisons are not performed. I thought the condition…
-
8
votes1
answer1608
viewsHow to apply the IF ELSE condition to selecting a column?
In Mysql, I have an old table entities where the column gender is in the format ENUM, containing values of the type: "i", "m", "f". When migrating this data to the new structure of this table, I…
-
7
votes4
answers714
viewsTrying to condense conditional with three possibilities
The problem is to present a result flexing to the plural if necessary, or "no": Let ni>=0 (number of items): switch(true){ case $ni==0: $html = ' (nenhum)'; break; case $ni==1: $html = ' (1…
-
6
votes2
answers982
viewsIs it possible to perform an assignment and comparison in if clauses in Java?
It is possible to assign and at the same time perform a comparison in an if clause in Java? For example: String linha = leitor.readLine(); String saida = ""; if (linha = leitor.readLine()) { saida…
-
5
votes6
answers636
viewsHow do you turn the average to red?
How do I make the average result turn red if the value is less than 20? Follows the code: <?php function media($p1,$p2,$p3) { $resultado = ($p1 + $p2 + $p3)/3; return $resultado; }…
-
5
votes1
answer435
viewsC# IF simplification
I have this code, and I’ve been searching for a way to simplify it using a ternary operator, but I’m not getting it because it says I can’t use decimal string: decimal per; if (nud_qtPedida.Value !=…
-
5
votes1
answer215
viewsComparison of value within data frame
Hello, I have a database, with about 50000 remarks, as follows, only figurative values: nome<-c("joão","pedro", "joãoo") identificador<-c(123456,124578,123456) valor<-c(2145,350,23)…
-
5
votes3
answers464
viewsWhat is a Guard clause?
What is a Guard clause? Possible translations and synonyms: Custody clause Guard status Sentinel clause Prevention clause Protection clause Fuller definition. What are its advantages? The code is…
-
4
votes5
answers2024
viewsReplace If/Else with Case javascript
I would like to replace if/Else with Case because I believe it will be better for understanding the code since it will be a little long, but I cannot access the Array that will have the conditions…
-
4
votes3
answers30960
viewsHow to query in Mysql with two different conditions in WHERE
I have two queries that work perfectly separately, but I needed all their records together. Would be these: SELECT b.idBanca AS idB, b.DataHora AS dataHora, b.Sala AS sala, t.idTrabalho AS idT,…
-
4
votes2
answers305
viewsTurn positive values into negative values in a data.frame based on one condition in another column (R)
I have the following date. :: df <- data.frame(Qtd=c(100,200,300,400,500), op=c('V','C','C','V','V'), stringsAsFactors=F) How I can turn the values in the Qtd column to negative if the op column…
-
4
votes2
answers634
viewsHow to paint cell according to the value of a select?
I am in need of a help to format a <td> according to the outcome of select PHP. I thought about using jQuery but I don’t know much about it. <tr class=""> <td class=""><?php…
-
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
votes2
answers67
viewsHow to reverse series of denied conditions without affecting logic?
Could someone explain to me why this happens? My apk only works right if I put denial and do something: public class Main2Activity extends AppCompatActivity { private EditText nome, teste, cpf;…
-
4
votes4
answers837
viewsProblems with conditional structures
I started programming a little while ago and I’m doing some Python exercises. The problem is that the result variable always returns "Approved" even when the concept is "D" or "E". I’ve broken my…
-
4
votes3
answers551
viewsif and Else with almost equal blocks
In Python, suppose I have a function: def func(x): if x%2 == 0: j = x/2 print(j) else: j = x print(j) Don’t mind the logic of the code, it’s just a simple example. The if and Else blocks are almost…
-
4
votes2
answers171
viewsIdentify cases with multiple conditions in multiple columns in R
I have a dataframe with 20 students and I need to identify the students who attended stage 43 for two years or more. aluno <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,…
-
3
votes1
answer3024
viewsHow do I use the if and Else functions?
I’m having trouble with my job if and else, I started my programming studies a short time ago and didn’t understand very well how to use. It’s something like that? número = 2 If número == 2:…
-
3
votes2
answers465
viewsIs there a function that checks if a certain value is contained in a certain range?
Supposing: x=120,00 limites.inferior<-80 limites.superior<-160 limites<-c(limites.inferior,limites.superior) I am performing this procedure with a logical test: x.int<-x>=limites[1]…
-
3
votes2
answers407
viewsCompletion of mandatory fields
How do I force at least one of the two fields to be mandatory (is filled)? For example, the fields Celular and Telefone cannot be saved empty, only one of them. My code: //.. } else ((txtNome.Text…
-
3
votes3
answers135
viewsDifference of null and another proposition using this null object
If I have a code, for example: if(window!=null && window.isOpen()){ //todo } If window for null, Will he still try to call the second proposition or not check anymore? Because if he tries to…
java operators nullpointerexception null conditionasked 8 years, 2 months ago Mateus Carvalho 1,494 -
3
votes2
answers77
viewsmai() php function not working under conditions
I have a PHP that sends an email from a contact form, when this in the condition of the captcha verification, I receive the sent message, but the email is not delivered, and when I remove the…
-
3
votes2
answers249
viewsDo While enters infinite loop
I’m sure my mistake is in while, but I can’t understand what I did wrong. He goes into loop infinite. Follows the statement: Implement a program that receives 3 arguments from the command line. 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
votes2
answers1752
viewsIs it possible to evaluate a ternary expression with 3 possible values?
Let’s say I have this account: var total = valor1 / valor2; The result could be three possible values, like: total > 5 total > 0 and total < 5 a positive value Note: They are percentage…
-
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
votes1
answer80
viewsConditional Assignment in PHP
I’m studying PHP and came across a Feature which does not exist in Python (I do not know in other languages), which is the assignment in a conditional test: $file = fopen("arquivo.txt", "w");…
-
3
votes1
answer309
viewsR Delete data frame lines by condition
I have the following data set: Nome <- c("Laetia","Vouacapoua","Lecythis","Pourouma","Poraqueiba","Pseudopiptadenia", "Abarema"); I1 <- c(1,3,3,2,3,3,3); I2 <- c(1,3,1,3,3,3,3); I3 <-…
-
3
votes1
answer1797
viewsHow to use the if block with variable types in Python?
I am creating a program in Python and need that necessarily the data of the ID field are integer numbers. Basically I want to enter the block if depending on the type of variable I get. Example: ID…
-
3
votes2
answers194
viewsCondition to continue loop while invalid value
I wanted to know about this code: Algoritmo "Brincadeira2Ou1 " Var A, C, P: inteiro Inicio A <- 0 C <- 0 P <- 0 escreval ("(=====================2===OU===1=====================)") escreval…
-
2
votes0
answers32
viewsHow do I get a value of true or false from the database in Wordpress before the loop
I have a custom field to display a slide that is a boolean field! I want to make a condition before the loop if the result is true to display the slide if it is false I want this condition to be…
-
2
votes1
answer97
viewsProblem in condition to handle string
It was only supposed to work with lower-case letters and when it arrived at symbols it did not change, but they are being changed. What’s the problem? #include <stdio.h> int main() { char…
-
2
votes1
answer286
viewsOne method stopping the loop of another method
I have four objects (already instantiated) triangle, square, circle and a last picture, responsible for invoking both methods of each class of the respective objects, in order to draw a house, a…
-
2
votes3
answers7168
viewsTwo conditions in the same if() javascript loop
I can’t prevent the button submit to carry out its action if the information typed is not equal, someone could help me? HTML <form method="post" action="php/cadastro.php"> <span…
-
2
votes1
answer2251
viewsUse if/Else condition inside a while
Good morning!! I’m in need of some help. In the code below, I submit a file .txt delimited by ";". However, within the While, in the array, I would like to include a condition, example: while (…
-
2
votes2
answers1175
viewsFind a particular line or specific value of a matrix vector in R
How to build a function that evaluates if any row of the matrix mat is equal to the vector vec both in the code below: set.seed(000) mat <- matrix(rnorm(20),4,5) vec <- c(1.3297993,…
-
2
votes2
answers776
viewsVisualg - Boolean result
I built this algorithm into Visualg: algoritmo "semnome" var inicio se 3 = "a" entao escreva("igual") senao escreva("diferente") FimSe fimalgoritmo And I don’t understand, why the condition is…
-
2
votes1
answer783
viewsWhat is the problem with this code that takes the highest and lowest value?
I want to display the sum of the numbers typed as well as the largest and smallest number typed, only with while, if and else: contador = 1 maior = 0 menor = 0 S = 0 # 1º NÚMERO A SER SOMADO while…
-
2
votes1
answer34
viewsHow to create a copy of an element, through its property
I want clone only images whose the attribute alt be "photo". Code var str = document.getElementById('A'); var clone = str.cloneNode(true); document.getElementById('B').appendChild(clone); <span…
-
2
votes1
answer158
viewsIs it possible to put an OR in the FOR stop condition?
It is possible to put two conditions to stop one for? In my example I’m trying to do this: function criacaoParidade(entrada) { entrada = Array.from(entrada); func = positionBit(entrada); tam =…
-
2
votes1
answer266
viewsternary or if and Else condition with PHP
I would like to know, when I should use these kinds of conditions, I have already made the test returns me the same thing, but what is the difference? I believe it is not only decrease lines, but…