Questions tagged [conditional-statements]

"In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Apart from the case of branch prediction, this is always achieved by selectively altering the control flow based on some condition." -- Wikipedia

Read on Wikipedia

19093 questions
123
votes
3 answers

MySQL IN condition limit

Hey, I have to use IN condition in my MySQL statement with a large set of ids. Example SELECT * FROM users WHERE id IN (1,2,3,4...100000) Is there a limit if items the IN statement can have?
xpepermint
  • 35,055
  • 30
  • 109
  • 163
123
votes
14 answers

How to compare strings in C conditional preprocessor-directives

I have to do something like this in C. It works only if I use a char, but I need a string. How can I do this? #define USER "jack" // jack or queen #if USER == "jack" #define USER_VS "queen" #elif USER == "queen" #define USER_VS "jack" #endif
frx08
  • 4,222
  • 8
  • 37
  • 45
117
votes
7 answers

VBA - how to conditionally skip a for loop iteration

I have a for loop over an array. What I want to do is test for a certain condition in the loop and skip to the next iteration if true: For i = LBound(Schedule, 1) To UBound(Schedule, 1) If (Schedule(i, 1) < ReferenceDate) Then …
Richard H
  • 38,037
  • 37
  • 111
  • 138
117
votes
6 answers

MySQL select with CONCAT condition

I'm trying to compile this in my mind.. i have a table with firstname and lastname fields and i have a string like "Bob Jones" or "Bob Michael Jones" and several others. the thing is, i have for example Bob in firstname, and Michael Jones in…
Alex K
  • 6,737
  • 9
  • 41
  • 63
115
votes
3 answers

Syntax for if/else condition in SCSS mixin

Hi I'm trying to learn SASS/SCSS and am trying to refactor my own mixin for clearfix what I'd like is for the mixin to be based on whether I pass the mixin a width. thoughts so far (pseudo code only as I will be including other mixins) @mixin…
clairesuzy
  • 27,296
  • 8
  • 54
  • 52
113
votes
8 answers

#ifdef #ifndef in Java

I doubt if there is a way to make compile-time conditions in Java like #ifdef #ifndef in C++. My problem is that have an algorithm written in Java, and I have different running time improves to that algorithm. So I want to measure how much time I…
jutky
  • 3,895
  • 6
  • 31
  • 45
111
votes
4 answers

How does "do something OR DIE()" work in PHP?

I'm writing a php app to access a MySQL database, and on a tutorial, it says something of the form mysql_connect($host, $user, $pass) or die("could not connect"); How does PHP know that the function failed so that it runs the die part? I guess I'm…
chustar
  • 12,225
  • 24
  • 81
  • 119
110
votes
14 answers

How to check whether a str(variable) is empty or not?

How do I make a: if str(variable) == [contains text]: condition? (or something, because I am pretty sure that what I just wrote is completely wrong) I am sort of trying to check if a random.choice from my list is ["",] (blank) or contains…
user1275670
  • 1,215
  • 2
  • 8
  • 9
110
votes
13 answers

MySQL Conditional Insert

I am having a difficult time forming a conditional INSERT I have x_table with columns (instance, user, item) where instance ID is unique. I want to insert a new row only if the user already does not have a given item. For example trying to insert…
The Unknown
  • 19,224
  • 29
  • 77
  • 93
109
votes
3 answers

querying WHERE condition to character length?

I have a database with a large number of words but i want to select only those records where the character length is equal to a given number (in example case 3): $query = ("SELECT * FROM $db WHERE conditions AND length = 3"); But this does not…
faq
  • 2,965
  • 5
  • 27
  • 35
106
votes
4 answers

Angular 2 Pipe under condition

Is it possible in Angular 2 to apply a pipe under condition? I would like to do something like: {{ variable.text | (variable.value ? SomePipe : OtherPipe) }} If not, what is the preferred way to achieve this effect?
Daniel Kucal
  • 8,684
  • 6
  • 39
  • 64
106
votes
10 answers

Conditional build based on environment using Webpack

I have some things for development - e.g mocks which I would like to not bloat my distributed build file with. In RequireJS you can pass a config in a plugin file and conditonally require things in based on that. For webpack there doesn't seem to be…
Dominic
  • 62,658
  • 20
  • 139
  • 163
104
votes
13 answers

Determining if a number is either a multiple of ten or within a particular set of ranges

I have a few loops that I need in my program. I can write out the pseudo code, but I'm not entirely sure how to write them logically. I need - if (num is a multiple of 10) { do this } if (num is within 11-20, 31-40, 51-60, 71-80, 91-100) { do this…
user3419168
  • 1,135
  • 2
  • 8
  • 16
103
votes
4 answers

In Twig, check if a specific key of an array exists

In PHP we can check if a key exists in an array by using the function array_key_exists(). In the Twig templating language we can check if an variable or an object's property exists simply by using an if statement, like this: {% if app.user %} do…
user852610
  • 2,205
  • 7
  • 36
  • 46
102
votes
9 answers

Run an Ansible task only when the variable contains a specific string

I have multiple tasks depend from the value of variable1. I want to check if the value is in {{ variable1 }} but I get an error: - name: do something when the value in variable1 command: when: "'value' in {{ variable1 }}" I'm using…
mndhr
  • 1,409
  • 5
  • 13
  • 17