Tutorial by Examples: cond

The intrinsic pack function packs an array into a vector, selecting elements based on a given mask. The function has two forms PACK(array, mask) PACK(array, mask, vector) (that is, the vector argument is optional). In both cases array is an array, and mask of logical type and conformable with...
Most browsers, when configured to block cookies, will also block localStorage. Attempts to use it will result in an exception. Do not forget to manage these cases. var video = document.querySelector('video') try { video.volume = localStorage.getItem('volume') } catch (error) { alert('If...
See this Q&A question if you don't know what race conditions are. The following code may be subject to race conditions : article = Article.objects.get(pk=69) article.views_count += 1 article.save() If views_count is equal to 1337, this will result in such query: UPDATE app_article SET vi...
Orders Table CustomerIdProductIdQuantityPrice12510013220014150021450356700 To check for customers who have ordered both - ProductID 2 and 3, HAVING can be used select customerId from orders where productID in (2,3) group by customerId having count(distinct productID) = 2 Return value:...
if v:version >= 704 " Do something if Vim is the right version. endif if has('patch666') " Do something if Vim has the right patch-level. endif if has('feature') " Do something if Vim is built with 'feature'. endif See :help has-patch and :help feature-li...
Tag syntax Parameters AttributeRequiredTypeDefaultDescriptionconditiontruestringCondition that manages the loop. Cannot contain math symbols like <, > or =. Must use ColdFusion text implementations like less than, lt, greater than, gt, equals or eq. Final value of x is 5. <cfset x = 0 /...
The @if control directive evaluates a given expression and if it returns anything other than false, it processes its block of styles. Sass Example $test-variable: true !default =test-mixin @if $test-variable display: block @else display: none .test-selector +test-mixin ...
A common problem is having a collection of items that all need to meet a certain criteria. In the example below we have collected two items for a diet plan and we want to check that the diet doesn't contain any unhealthy food. // First we create a collection $diet = collect([ ['name' => ...
Conditional contexts in Lua (if, elseif, while, until) do not require a boolean. Like many languages, any Lua value can appear in a condition. The rules for evaluation are simple: false and nil count as false. Everything else counts as true. if 1 then print("Numbers work.") ...
Conditional expressions can be done with ~[ and ~]. The clauses of the expression are separated using ~;. By default, ~[ takes an integer from the argument list, and picks the corresponding clause. The clauses start at zero. (format t "~@{~[First clause~;Second clause~;Third clause~;Fourth cl...
A data race or race condition is a problem that can occur when a multithreaded program is not properly synchronized. If two or more threads access the same memory without synchronization, and at least one of the accesses is a 'write' operation, a data race occurs. This leads to platform dependent, p...
Dim sites() As String = {"Stack Overflow", "Super User", "Ask Ubuntu", "Hardware Recommendations"} Dim query = From x In sites Where x.StartsWith("S") ' result = "Stack Overflow", "Super User" Query will be enumerable objec...
UPDATE person SET state = 'NY' WHERE city = 'New York';
A powerful alternative to virtualenv is Anaconda - a cross-platform, pip-like package manager bundled with features for quickly making and removing virtual environments. After installing Anaconda, here are some commands to get started: Create an environment conda create --name <envname> pyth...
(defun fn (x) (cond (test-condition1 the-value1) (test-condition2 the-value2) ... ... ... (t (fn reduced-argument-x)))) CL-USER 2788 > (defun my-fib (n) (cond ((= n 1) 1) ((= n...
(defun fn (x) (cond (test-condition the-value) (t (fn reduced-argument-x))))
Ruby has an or-equals operator that allows a value to be assigned to a variable if and only if that variable evaluates to either nil or false. ||= # this is the operator that achieves this. this operator with the double pipes representing or and the equals sign representing assigning of a valu...
A While loop starts by evaluating a condition. If it is true, the body of the loop is executed. After the body of the loop is executed, the While condition is evaluated again to determine whether to re-execute the body. Dim iteration As Integer = 1 While iteration <= 10 Console.Writeline(ite...
When a runtime error occurs, good code should handle it. The best error handling strategy is to write code that checks for error conditions and simply avoids executing code that results in a runtime error. One key element in reducing runtime errors, is writing small procedures that do one thing. Th...
In Common Lisp, if is the simplest conditional construct. It has the form (if test then [else]) and is evaluated to then if test is true and else otherwise. The else part can be omitted. (if (> 3 2) "Three is bigger!" "Two is bigger!") ;;=> "Three is bigger...

Page 3 of 9