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
-
-1
votes2
answers54
viewsfor/if PHP omitting element
I have a big problem. I have a PHP/LARAVEL system that issues PDF reports. The system it is omitting an element when placing it in an array. I believe it’s time to assemble the loop and make the…
-
-1
votes2
answers110
viewsMount "if"s according to criteria
I’m having a question on the condition I’m willing to put in my system. In case the site will check if the "Paid" is with the result 1; if you have 1, it will put "Delivered", but if you have 0 it…
-
-1
votes2
answers52
viewsPython creating conditions or loop
(I wanted something that when he entered one of the levels more questions would appear and in case he wants to leave press a key) print("Agora ira começar um joguinho. \n") print("Comece digitando…
-
-1
votes2
answers57
viewsIf condition breaks before changing the value of the variable
The idea of the system is, while one of the bollean is false, the send button releases to the click. I compare the src of the files, and if one of them is equal to './img/armerVermelha.png', the…
-
-1
votes1
answer54
viewsHow to reduce the number of elifs to find the letter that is most used at the beginning of the names?
lista_nomes = [] lista_idade = [] lista_sexo = [] idade_cont_menores = 0 idade_cont_maiores = 0 sexo_op = ['m', 'f'] sexo_cont_masculino = 0 sexo_cont_feminino =…
-
-1
votes1
answer2411
viewsHow to compare two separate columns in excel and check if the data of one is inside another?
If you could help me with this case, I’d really appreciate it. I am trying to make a column with the comparison filter between two columns of excel, returning the value that are common to the two…
-
-1
votes1
answer245
viewsUtopian Tree Exercise, Tree of Life etc. etc
Good morning! I am taking the Santander course, and the last challenge is the famous calculation of the height of the tree of life. I have a very specific problem. Rather, it follows the statement:…
-
-1
votes2
answers7986
viewsMake a Program that reads three numbers and shows them in descending order. Python
Hello, I’m trying to make an algorithm that reads three numbers in Python and delivers them in descending form. The code is right, but I know you can write better only using logic... a =…
-
-1
votes1
answer293
viewsPython programming (calculating average with shares, average case less than set value)
I need your help to solve an issue of my programming course, I have an initial activity and do not know where to continue, I need to create a program that gets 2 grades, disappear and divide by two…
-
-1
votes3
answers452
viewsJavascript - If and Loop
I’m trying to answer a question inside a platform, and I’m not being able to adjust the code as the algorithm wants. I am receiving the following errors : 1- You must have an if validating the…
-
-1
votes1
answer119
viewsJavascript: Problems running a function. How to improve code?
Hello, I am doing an introductory Javascript course and, although I can print the desired result of the exercise, the platform does not recognize my code. I would like you to help me improve the…
-
-1
votes1
answer39
viewsError reading a python txt file and adding variable
I have a problem with an automation I use. I use a TXT with some information but in IF I don’t 'recognize' the variable I added in TXT. import sys import webbrowser import random import time import…
-
-1
votes1
answer46
viewsProblem executing function with While loop and If condition
I need to perform an exercise, which prompts a system that reads 20 numbers, then sums them up and then displays the result on the screen. The statement asks to use only While. So I made the code…
-
-1
votes1
answer114
views -
-1
votes1
answer40
viewsJavascript IF and ELSE difficulty - Return result text on screen
DOUBT: How to make an IF ELSE with javascript to display a text (Ex: Approved) when locating a given word (Ex: Green). My current code is this below, but it’s not working and I can’t find the…
-
-1
votes2
answers49
viewsProblem when receiving data from the database with if/Else
Guys I have a problem in my php, I want to select the name of people according to a code and for this I made an IF, but the code that should take the values of the database and print on the page is…
-
-1
votes1
answer47
viewsif Else - Does the position of the keys "{}" make a difference in the result?
I’m making web Scrapping from a website. And for that I need to check if a data.frame exists or not. Besides not being working, I realize that I have different results only changing the position of…
-
-1
votes1
answer42
viewsConverting total hours of a month into days and hours
Hello! I am working on a data_set in which the time measure is in Total Hours Races of the month. Going from hour 1 to hour 734. I want to convert this measure of time into hours of the month per…
-
-1
votes1
answer23
views -
-1
votes1
answer59
viewsThe parameter of my function, when 1, assumes Boolean value and when False assumes Number value. How do I fix this? Javascript doubt
I’m right at the beginning of my studies with JS, so I got a little lost in this exercise. I need to type check the single parameter of the 'check' function. When it is True, it returns False and…
-
-1
votes0
answers21
viewsPython if function
Hello, In a database with vaccine information per day, I want to compare whether the sum of each laboratory (Sinovac, Pfizer and Astrazeneca) is different from the reported total. If it is, I want…
-
-2
votes2
answers198
viewsPHP: If Result with Function
I’m having a little problem using If with a Function to show a result. function estaParaExpirar($data, $dias){ return(strtotime($data) < strtotime("+".$dias. "days") ); } if…
-
-2
votes1
answer72
viewsAndroid Studio App
I am developing an application that is a dictionary of chords for guitar. And as there are numerous chords, consequently I have numerous activities. The problem is that the application will be very,…
-
-2
votes2
answers293
views"if" does not match the condition
I’m trying to apply a if in my code, but it’s coming wrong: <?php echo $usu_id . "<br />"; echo $centraliz . "<br />"; echo $marca . "<br />"; if($centraliz = "S"){ echo "É…
-
-2
votes1
answer692
views -
-2
votes1
answer57
viewsWhy doesn’t print return all the items in a list?
The following code should return all cars from the following list: cars = ['audi','bmw','subaru','toyota'] for car in cars: if car == 'bmw': print(car.upper()) else: print(car.title()) But he only…
-
-2
votes3
answers659
views -
-2
votes1
answer1738
viewsHow to make an if with a higher and a lower value?
I was wondering if it’s possible to make a if or a for in PHP as follows: $valor = 7 if ( $valor se o valor for maior que > 5 menor que < 10) { //... Comando a ser executado ... }else if (se o…
-
-2
votes2
answers68
viewsComparison of numbers read with "io.read()" does not result in true as expected
I tried to put 1 and the second print was not. If I change x=io.read() for "x=1" it works normally Follows the code x = io.read() if x ~= 0 then print(x.." diferente de 0") end if x == 1 then…
-
-2
votes1
answer36
viewsBash - current date and calendar with "if Else"
#!/bin/bash echo "1 - calendario" echo "2 - data" echo "opção: " read var if [$var -eq 1]; then calendario=$(cal) echo $calendario elif [$var -eq 2]; then now=$(date) echo $now else echo "opção…
-
-2
votes1
answer95
viewsI need help with the PHP language
So guys I’m having a hard time in a part of my code, as it is too big I will post only the part that is wrong: <?php try{ $entrar = $_POST["entrar"]; $cpf = $_POST["cpf"]; $senha =…
-
-2
votes1
answer173
viewsDifficulties with using IF
Good morning, you guys. I’m still a beginner in programming, I’m trying to write a simple program that calculates the coefficient of performance and reports the percentage of the course completed,…
-
-2
votes1
answer186
viewsStatement for 2 arguments, how does it work?
I saw this statement in a code on codewars and I couldn’t understand how it works: def multiple_of_index(arr): return [val for index, val in enumerate(arr) if index and val % index == 0]…
-
-2
votes2
answers160
viewsJob Seekers Information Filter
A program that provides information on job applicants: The number of candidates per sex.... There is an error in this if, ta returning only m or just f package livroex_pag69; import…
-
-2
votes1
answer2656
viewsCalculating Javascript false/rue relationship
Could help me solve this question, it should return false/true! We need to create a function that checks if two people are half brothers! In order for you to solve this exercise, we have defined for…
-
-2
votes2
answers225
viewsLogic test inside the Python array
In the R I can have this structure var1 <-TRUE var2 <-FALSE paste0("ANO_544, SEMANA", if(var1 == TRUE){", COD_NEGOCIO"}, if(var2 == TRUE){", CATEGORIA"}, ", MODULADO") And I got an answer:…
-
-2
votes1
answer93
viewsphp function cannot compare words with accents
I have a function that compares 2 words, but when removing the accents, it still identifies as different words: function acento($str, $from, $to) { $keys = array(); $values = array();…
-
-2
votes1
answer91
viewshow to decrease ifs? in python
I’m starting in programming and would like to know if I have how to decrease the uses of ifs """ Classification of a person by height and weight alt = float(input("Digite a sua altura")) p =…
-
-2
votes2
answers139
viewsWhat’s wrong with my code?
I wanted to create a system that asked the nationality of the user and if he answered "Brasileiro", the if would lead to a response. Should any other nationality, the else would take you to another,…
-
-2
votes1
answer39
views(Language C) I’m not really able to compare if between two chars
This is the initial menu code of the program: #include<stdlib.h> #include<stdio.h> #include<conio.c> #include<time.h> #include<locale.h> void inicio(); void logar();…
-
-2
votes1
answer33
viewsHow to delete only the "box" category from the menu view?
I have searched but without success, I want the box category not to be displayed in a menu but not deleted, I just want it not to be displayed and continue to exist, this menu is all categories…
-
-2
votes1
answer85
viewsException error in thread "main" java.lang.Numberformatexception: For input string:
I’m having trouble getting my program to return the IF in a correct way, when I put the FOR it counts the number of times it is in the variable, if I type an input less than 14 it instead of falling…
-
-3
votes1
answer129
viewssyntax error, Unexpected 'if' (T_IF)
What’s the mistake? $sql = "SELECT item1, item2, item3 FROM tab_exemplo WHERE" if (isset($item3)) {echo 'quartos LIKE :A';} if (isset($item2) || isset($item1) || isset($item4)){echo 'AND'} if…
-
-3
votes2
answers94
viewsWhat does the expression "!(errS&errE)" do in the if?
In a piece of code I need to understand, a new syntax appeared to me on if: if (!(errS&errE)) { fprintf(stderr, "\nFALTA ARGUMENTOS\n"); if(!errS) fprintf(stderr, "-s NOME ARQUIVO SAIDA \n");…
-
-3
votes1
answer76
viewsam I new to the programming will you help me?
would like the result of Ifs to enter directly into the variable (Lista2) and to be printed all example numbers [1,3,2,5,5,7,8]. My code so far: lista = [] lista2 = [] while len(lista)+1 <= 7:…
-
-3
votes1
answer68
viewsWhy does my function only return "even"?
function parimp(n){ for(var i = 0; i <= n; i++){ if(i % 2 == 0){ return "par"; }else{ return "impar"; } } } var s =…
-
-3
votes1
answer33
viewsProper fraction, improper and apparent in C language
I am trying to create the following program in C: Make a program that receives 2 numbers referring to the numerator and denominator of a fraction and inform if it is a fraction of its own, improper,…
-
-3
votes1
answer40
viewsHow do I put a close button on my python file?
I’m starting in python and I’m writing a code, but when all the actions end the program closes, how do I put a command where for example click ESC and it closes? I want that when the person does not…
-
-3
votes3
answers174
viewsCondition "If" does not enter the structure
I’m having a problem with my code,I get an xlsx file, and I do the whole procedure correctly. but the file comes with some commas that need to be removed, and when I do the if to check if it has the…
-
-3
votes1
answer89
viewsYou are giving variable not defined within an if
Art. 42. Can adopt the over 18 (eighteen) years, regardless of marital status. § 1º Cannot adopt the ascendants and the brothers of the adopting. § 2º For joint adoption, it is indispensable that…