Questions tagged as 'if'

4
answers

IF, 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") chutar(); Now see the same with if ,...
asked by 23.11.2014 / 01:18
7
answers

How does this if / else work with "?" and ":"?

I am studying JavaScript and I have doubts about the different ways of doing if / else . For example, this: foo ? foo : foo How exactly does it work?     
asked by 08.02.2014 / 18:15
2
answers

Differences between If and ternary operator?:

Is there a performance difference between using an if and a ternary operator in C #? I use Resharper (Productivity Tool for VS) , he insists that ternary operator is better but you do not explain why. Code, before Refactoring: if (i...
asked by 28.05.2014 / 16:01
4
answers

What good practice when throwing exception within if?

What is the best practice in this case, to use else even though you know that if will throw an exception or not? option 1 (with else ): if (condicao){ throw new RuntimeException("Mensagem"); }else{ System.out.println("Não deu exce...
asked by 14.01.2014 / 11:28
2
answers

What's the difference between Switch, Case and If, Else?

I would like to know the difference between switch .. case and if .. else . What offers better "performance"?     
asked by 13.04.2015 / 20:33
2
answers

How to simplify the following IF in PHP?

I had to do a check to concatenate content to a variable, but I think the service got a little "hog" and wanted to see if anyone could help me simplify this check. if($IdUserOnline2){ $IdsInteracoes .= implode(',',$IdUserOnline2); if($...
asked by 20.03.2014 / 18:24
1
answer

Why is using String in a switch block more efficient than in an if-else block?

According to Java documentation : / p>    The Java compiler generally generates more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.     
asked by 26.08.2015 / 16:37
1
answer

Doubt about the IF

Does the IF function only work with Integer or does it also work with String? I was trying to create a program that would ask if you are sure you want to create the password. You can check the code below: package com.programas.Verificacao2; im...
asked by 27.01.2016 / 02:07
1
answer

JavaScript ternary condition with only one value

A fairly basic JavaScript question, on a ternary condition how can I do to take action only on an if without the need of the else? Example (test) ? test1() : test2(); If you do not want anything to happen at Else, how would you look?...
asked by 06.05.2014 / 19:45
1
answer

Do you really need the "Then" at the end of the If block?

The Visual Basic .NET compiler seems to ignore the reserved word Then , which is at the end of the If block. If (1 + 1 = 2) Then Console.WriteLine("Passou no teste.") End If And now, without Then : If (1 + 1 =...
asked by 22.10.2015 / 00:29