if statement - If 2 of 3 conditions are met (w/o || "OR") -


q&a

how can check if 2 of 3 conditions met without doing ton of or-statements in conditional-statement.

i.e.

if (((a==true)&&(b==true))||((b==true)&&(c==true))||((c==true)&&(a==true))) {

use conditional statements (a==true) return value 1 or 0 in if statement...

i.e.

if (a==true) { same if ((a==true)==1) {

because conditionals in form if (1) { else if (0) {

to shorten
if (((a==true)&&(b==true))||((b==true)&&(c==true))||((c==true)&&(a==true))) {
assign each conditional == statement numeric value either 1 or zero, add conditionals , check if value greater 1 (meaning or more of conditional met) because if condition not == true returns 0 if returns 1 , adding them gives numeric value...

shortened form:

if ((a==true)+(b==true)+(c==true)>1) {

and can shorter if using language handles bool way obj-c handle's bool.

if ((a)+(b)+(c)>1) {


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -