IF() statement alternative in SQLite

For generic SQL you can use CASE: CASE is used to provide if-then-else type of logic to SQL. Its syntax is: SELECT CASE (“column_name”) WHEN “condition1” THEN “result1” WHEN “condition2” THEN “result2” … [ELSE “resultN”] END FROM “table_name” From http://www.sqlite.org/lang_expr.html section “The CASE expression” E.g. UPDATE pages SET rkey = rkey + 2, lkey = … Read more

How to format multiple ‘or’ conditions in an if statement

I use this kind of pattern often. It’s very compact: Define a constant in your class: private static final Set<Integer> VALUES = Set.of(12, 16, 19); // Pre Java 9 use: VALUES = new HashSet<Integer>(Arrays.asList(12, 16, 19)); In your method: if (VALUES.contains(x)) { … } Set.of() returns a HashSet, which performs very well even for very … Read more

Are JavaScript variables declared in the body of an if statement scoped to the body?

1) Variables are visible for the whole function scope. Therefore, you should only declare them once. 2) You should not declare the variable twice in your example. I’d recommend declaring the variable at the top of the function, then just setting the value later: function actionPane(state) { var structure; if(state === “ed”) { structure = … Read more