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
-
2
votes2
answers100
viewsHow to know if a Nsarray is empty (or void) using IF
I need to know if a Nsarray is empty or void using an if. Code: NSArray* array; if( array == nil) { // Fazer algo }
-
2
votes1
answer48
viewsSelect notes to be printed
I need to print only the notes above >=6, in which place of the code I put the if or some other instruction? I tried and I couldn’t find the right place. #include <iostream> #include…
-
2
votes2
answers4787
viewsIF syntax inside an ECHO
I’m having a syntax problem trying to place a if within a echo in PHP. Check out the code: foreach($resultadoBusca as $escrever){ echo "<tr><td>" . $escrever['cod_votoran'] .…
-
2
votes1
answer244
viewsFour different conditions using awk if (Unix)
Hello I need to do an awk if command using 4 different conditions together, example of my input just for a few lines (I have an input with thousands of lines) chr17_30 1 chr1_72 0 chr1_46 2 chr1_47…
-
2
votes1
answer530
viewsAlternative to If/Else
I have the following code: private void maskedTextBoxEAN_Leave(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(maskedTextBoxEAN.Text)) if…
-
2
votes1
answer1350
viewsHow to go through all the records in the database table?
Good afternoon, you guys! I’m starting in PHP and I already have a little problem. Is the following: I need to go through all the records in the bank table, so I can validate if such a value already…
-
2
votes1
answer199
viewsQuestion about radio button
I have a form that has two buttons radio: 1-masc 2-fem. I want when one of them has pressed, and I click "calculate" he pull the if indicated for each radio. <form name="calc" method="post"…
-
2
votes3
answers511
viewsWhat is the most recommended "Try" or "if"
{ public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { double SalarioBase = 0, Descontos = 0, Vantagens = 0; try { SalarioBase =…
-
2
votes3
answers16313
viewsComparison of char in C
I need to find out if each element of a chained list is a vowel or not. How can I fix my code? int BuscaNv(LISTA* resp){ NO* atual = resp->inicio; while(atual){ if(atual->letra == 'a' || 'e'…
-
2
votes2
answers4910
viewsWhen to use IF with ENDIF?
Under what circumstances should the: IF(CONDICAO) : ELSE: ENDIF;
-
2
votes2
answers778
viewsEmpty if declaration in function
It is possible to create a function that ends with an empty if statement and allows the code that called that function to determine if action? Example: def if(): if x>6: x = input("Valor de x")…
-
2
votes3
answers160
viewsWhat is the logic behind this function?
Why the result of L1 is: [2, 3, 4] instead of [3, 4]? def remove_dups(L1, L2): for e in L1: if e in L2: L1.remove(e) L1 = [1, 2, 3, 4] L2 = [1, 2, 5, 6] remove_dups(L1, L2) print(L1) I tested in…
-
2
votes1
answer60
viewsReturn message from Else
I’m making a very simple example using Django. In my view I have the following : def index(request,idade): string = ''' {% if idoso >= 65 %} Você já é idoso {% else %} Você não é idoso {% endif…
-
2
votes1
answer341
viewsElse does not work in PHP
I’m trying to use the code below, but the else does not work. Returns error Parse error: syntax error, unexpected 'else' (T_ELSE) <?php if ($status == 'True') ?> <div class="col-lg-3…
-
2
votes1
answer10388
viewsHow to present only negative values in C?
I have three variables : int numero1,numero2,numero3; After you have declared them, I am asked the user to fill them in : printf("Digite o primeiro numero inteiro: "); scanf("%d", &numero1);…
-
2
votes2
answers363
viewsif-Else command is not working
In one of the exercises of a book I’m reading, I’m asked to trace a person’s "profile" according to the year she was born (like those Facebook tests) but in order to limit the possibility of what is…
-
2
votes3
answers191
viewsLogical operator || in C# does not work
I’m trying to do an exercise where in a range of 0 to 30 I want to know which numbers are divisible by 3 or 4. Working with a if for every situation works. But if I try to use the logical operator…
-
2
votes1
answer46
views"If <condition> Then" block makes no sense
I am in charge of maintaining a Vbscript application, but my main programming languages are Java (7+), Javascript and PHP (5.4+). During code review to refactoring the horrifying lines macaroni that…
-
2
votes1
answer64
viewsGroup result through a conditional
I wonder if in Mysql or any other Bank you have the possibility to use GROUP BY with a conditional. I will try to explain I have a status column that can have the value true and false, would like to…
-
2
votes3
answers1276
viewsA: Creating a new variable using if and Else
I’m with a base of 9 million lines. I’m trying to make a new variable called base$trs_localidade using the variable base$iso_pais being: base$iso_pais<- c( '076', '840', '076','442' , '052' ,…
-
2
votes2
answers113
viewsisinstance() does not produce the expected result after a data entry
I made the following example of factorial using function isinstance(). def factory(n): if not isinstance(n,int) or n<0: print('NAO E NUMERO INTEIRO VALIDO:\n') return None if n==0: return 1 else:…
-
2
votes2
answers78
viewsCondition does not enter as entered
No matter what I type is falling on the first if, if I type m, M or even 10 will fall in the first if. I want that if the user type f or F appears feminine and the same goes for M or m. Letra =…
-
2
votes1
answer159
views"if" elegant in PHP
(!file_exists($pathFize) ? $response = false : $response = true); if ($response == true) { //executa o código ok } I would like suggestions on how to do this more elegantly, remembering that all…
-
2
votes2
answers484
viewsHow to use multiple answers for the same variable in just one if?
It is possible to use only one if for several possible values of the same variable? For example: Instead of writing: var nome="" var nome=prompt("Digite seu nome"); if (nome === null){ alert(Você…
-
2
votes2
answers74
viewsDifferences of boolean return
I came across the following example: $umidade = 91; $vai_chover = ($umidade > 90); if ($vai_chover) { echo "vai chover"; } To $vai_chover returns a boolean in if, but I found too much code to do…
-
2
votes1
answer41
viewsWhy does this code always return False?
Can anyone explain to me why it always returns false???? function ValidationProcessDoc( ext ){ if ( ext === 'TXT' || 'DOC' || 'XLS' || 'PPT' ) { return false; } else if ( ext === 'PDF' || 'HTM' ||…
-
2
votes1
answer519
viewserror: assignement to Expression with array type
I am trying to compile the code below for a list of exercises of my course introduction to programming but the codeblocks presents the error quoted in the title when I try to compile the code.…
-
2
votes1
answer129
viewsReturn in a Dataframe - Python
Good afternoon. I have a question about Python. I have an if where he has the conditional and Else, the Else he processes more than one file and I need to save all the information he reads inside a…
-
2
votes4
answers82
viewsHow do I create a list for possible answers in python?
Well... I wanted to make a list for possible user responses to input, for example: nom = str(input('Você gosta de mim? ')) lista = ['sim','claro','obvio'] if nom == lista: print('obrigado, bom…
-
2
votes1
answer46
views -
2
votes1
answer238
viewsPerforming array validation within another array
I have the following array, when I give a var_dump(): array(2) { [""]=> array(10) { ["js/ultramegamenu.js"]=> string(19) "js/ultramegamenu.js" ["js/padoo/jquery.cycle.js"]=> string(24)…
-
2
votes1
answer150
viewsDoes using or not block definition in simple "if" influence application performance?
Between one line and another there are some doubts that do not change the flow of decisions at all, but perhaps can influence the performance of the application by the amount of extra lines…
-
2
votes2
answers95
viewsDoubts with the use of IF / ELSE in C
When I run this code and type sex=M or =F, all conditions are executed as expected. When I type sex=m or =f, only the first condition is met, regardless of the age value. Can anyone explain me right…
-
2
votes1
answer105
viewsError creating variable inside IF
I was creating a script that always worked with me, however, I made a small change that almost blew my mind because I didn’t understand what happened and I didn’t find anything on the subject. Is…
-
2
votes3
answers85
viewsRepeat if again when validation fails
ConvInicial = str(input('Você: ')) if ConvInicial == 'Não estou passando bem' or ConvInicial == 'Estou com dor' or ConvInicial == 'Preciso de ajuda': print('O que você está sentindo?') RespDor =…
-
2
votes1
answer841
viewsLaravel 5, assuming variable in empty query?
I have a query, but sometimes this query returns an empty value (off the books). These query results are directed to generating a graph Highcharts, but when there are no values within the query, the…
-
2
votes1
answer104
viewsValidation does not enter the correct "if"
My code should have 4 validations and I’m using if and else if, but he’s only doing two of them, see the code below: double salario = 0; double p0 = 1.20; double p1 = 1.15; double p2 = 1.10; double…
-
2
votes2
answers55
viewsWhy do if or case tests not work in this subquery?
I am trying to run the following subquery within a view: (SELECT if(idnotas > 0, "não", "sim") FROM notas WHERE vendas_idvendas = p.vendas_idvendas ORDER BY idnotas DESC LIMIT 1 ) as…
-
2
votes2
answers143
viewsConditional structure does not work
Several times, especially when the second price is higher than the others, the program accuses that it is the cheapest. #Faça um programa que pergunte o preço de três produtos e informe qual produto…
-
2
votes4
answers487
viewsIF condition according to option field selection
I’m new to programming, I’m having a problem with my code: var micro = "Micro Inversores"; if (micro.equals(document.getElementById("tipo_unidade"))) { var tipo1 = 1; else var tipo1 = 0.8; }…
-
2
votes3
answers85
viewsWhy is my Condition Structure assigning a value to a variable?
My code below represents the scenario of keeping a feedback of 5 questions, where: Each question is worth 2 points Check if 3 students will hit the Feedback Calculate Each Student’s Individual Grade…
-
2
votes5
answers192
viewsCode executes a line that should be conditional
I am doing a job for college at C++ and, when performing an if/Else for a value of totalf equal to or different from 0, it is not obeyed. How do I exit display only a certain printf of correct…
-
2
votes2
answers377
viewsGame of popping polka dots on the screen
I only posted the JS, I think it’s enough, I’m still new to JS and programming so I know almost nothing of the commands, I want to compare the position of the balls and the area they appear so that…
-
2
votes3
answers653
viewsWhen to use if or Else If?
It’s a pretty silly thing, but during my writing I came across the following question: When is it really necessary to use if's or else if's in my code? Is there any impact on performance? I will put…
-
2
votes1
answer125
viewsI need help on the if and Else structure
I created two 'if and Else' structures to make the program write to the user using the plural correctly and as you can see below, I created two variables within the structures to assign the plural…
-
2
votes3
answers307
viewsHow to use if, Elif and Else
GOTHAM CITY Challenge (level 1) You are a police officer and need to report a criminal activity and on report you will give a number from 0 to 10 regarding the level of the crime. Make a code that…
-
2
votes1
answer71
views"Elif" does not allow to execute what is expected
If you do if each one alone and run with else, the calculation is correct. But using both (if and elif) does not recognize the differences and does not display the expected results. There will only…
-
2
votes2
answers571
viewsHow to handle multiple conditionals (if and if if followed) in Java and how to compress them?
Currently I have a small group of classes that implement a game of Snake with two players. I am implementing the movements as the keystrokes, currently the code is like this: // #----- Classe…
-
2
votes2
answers149
viewsCondition in PHP "if" to know if the sent Mysql command worked or not
I’d like to know what condition to put inside the if using PHP with Mysql database so it is possible to know if the command returned an error or not. As seen in the code below, I want to delete a…
-
2
votes1
answer53
viewsIs it possible to check an error of a function with an if()?
I’m using the package gtrends to pull some data from google.. This package allows you to download 5 Keywords at a time. That’s why I’m using a for() However, some Keywords I need to query are not in…