if-statement Questions
10
Solved
I want to check if a value is in an accepted range. If yes, to do something; otherwise, something else.
The range is 0.001-0.009. I know how to use multiple if to check this, but I want to know if...
Thoughtless asked 23/6, 2011 at 12:44
4
Solved
Is there a difference in performance between the if-else statement and the ternary operator in Python?
Bow asked 17/6, 2017 at 1:10
6
Solved
For some reason I can't remember how to do this - I believe there was a way to set a variable in Python, if a condition was true? What I mean is this:
value = 'Test' if 1 == 1
Where it would ho...
Sorrells asked 14/11, 2011 at 0:51
6
Solved
I want to use an if statement to check if the mouse is inside a certain div, something like this:
if ( mouse is inside #element ) {
// do something
} else {
return;
}
This will result in the f...
Cathey asked 21/4, 2016 at 10:43
11
Solved
This is my code for true on everything but empty string, null and false:
if (routeinfo["no_route"] == "" || routeinfo["no_route"] == null || routeinfo["no_route"] == false) {
// do sth ...
}
Th...
Almund asked 24/2, 2017 at 19:14
13
is there a way of typing for if like:
var = (cond) ? true : false;
or do we have to use this format?
if (cond)
true
else
false
end
Mackenie asked 8/4, 2011 at 12:18
5
Solved
So after some reading I've seen that
if (optional.isPresent()) {
//do smth
}
is not the preferred way to use Optional (http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.ht...
Wellchosen asked 20/1, 2016 at 14:5
7
Solved
I often find myself repeating some code at the end of all branches of an if-else chain:
Example:
if (cond1) {
// [...] code 1
// repeated code
} else if (cond2) {
// [...] code 2
// repeated ...
Lipoid asked 4/1, 2024 at 7:20
9
Solved
Given the following code:
if (is_valid($string) && up_to_length($string) && file_exists($file))
{
......
}
If is_valid($string) returns false, does the php interpreter still ch...
Farthing asked 17/4, 2011 at 16:25
2
Solved
I'm fairly new to VBA, and I can't find an easy way to test if any of the specified variables equal a specified value. The below seems to work, but is there an easier way to do it?
If variable1 = ...
Robledo asked 17/7, 2014 at 12:27
5
I'm writing a Kotlin program where type of variable is inferred but later on I wish to know the what type of value this variable stores. I tried following but it shows following error.
Incompatibl...
Scroggins asked 8/10, 2018 at 6:9
21
Solved
In Java, is it possible to write a switch statement where each case contains more than one value? For example (though clearly the following code won't work):
switch (num) {
case 1 .. 5:
System.o...
Protoxylem asked 3/6, 2012 at 20:11
5
in my view I have to output separately the one that is null and the one that is empty string
so i have this:
@if( $str->a == null)
... // do somethin
@endif
@if( $str->a == '')
... // do s...
Succussion asked 21/7, 2017 at 17:12
8
Solved
I'm trying to write a code that has a lot of comparison
Write a program in “QUANT.C” which “quantifies” numbers. Read an integer “x” and test it, producing the
following output:
x greater th...
Histo asked 7/1, 2014 at 12:59
9
Solved
for the following code
a =func()
if a != None:
b.append(a)
a can be assigned to None, is there a way to avoid the if statement and only use one line of code?
original problem is the following...
Sheriff asked 11/1, 2012 at 20:58
8
Solved
I want to have a javascript file which checks if current time is between 7pm and 7am. If so it should change the background color on my website to X.
If the current time is not between 7pm and 7am...
Acrefoot asked 3/8, 2013 at 9:35
11
Solved
So I'm using a shorthand JavaScript if/else statement (I read somewhere they're called Ternary statements?)
this.dragHandle.hasClass('handle-low') ? direction = "left" : direction = "...
Sculpin asked 19/7, 2012 at 5:32
30
Solved
How do I perform an IF...THEN in an SQL SELECT statement?
For example:
SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product
Callimachus asked 15/9, 2008 at 14:34
25
Solved
I have a string that I load throughout my application, and it changes from numbers to letters and such. I have a simple if statement to see if it contains letters or numbers but, something isn't qu...
Lazaro asked 13/5, 2012 at 22:5
13
Solved
I know how to use both for loops and if statements on separate lines, such as:
>>> a = [2,3,4,5,6,7,8,9,0]
... xyz = [0,12,4,6,242,7,9]
... for x in xyz:
... if x in a:
... print(x)
0,4,6...
Ferry asked 8/8, 2011 at 11:56
5
Solved
What's the best, preferred way of writing if shorthand one-liner such as:
expression ? $foo : $bar
Plot twist: I need to echo $foo or echo $bar. Any crazy tricks? :)
Jerz asked 27/11, 2013 at 3:13
6
Solved
I would like to compare two variables to see if they are the same, but I want this comparison to be case-insensitive.
For example, this would be case sensitive:
if($var1 == $var2){
...
}
But I...
Unciform asked 29/3, 2011 at 13:45
23
Solved
I am trying to solve the Leet Code challenge 14. Longest Common Prefix:
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return ...
Sluiter asked 8/8, 2021 at 16:37
4
Solved
Is this:
if(x != y)
{
}
different from this:
if (x is not y)
{
}
Or are there no differences between the two conditions?
Beverage asked 17/11, 2021 at 20:20
11
Solved
A coworker claimed recently in a code review that the [[ ]] construct is to be preferred over [ ] in constructs like
if [ "`id -nu`" = "$someuser" ] ; then
echo "I love yo...
Tunstall asked 21/3, 2009 at 15:28
© 2022 - 2025 — McMap. All rights reserved.