<value> = <condition> ? <value> : <value>
Operators: Item selector "[]" Operators: Select "? :"Select one of two Glossary: Valuevalues based on a Flow controlcondition.
Flow control: if … then Flow control: try … thenThe Flow controlcondition must be a numeric Glossary: Valuevalue Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and is considered 'true' Flow control: if … thenif it is non-zero.
Flow control: if … then Flow control: if … thenIf the Flow controlcondition is true, Flow control: if … then Flow control: try … thenthen Flow control: if … then Flow control: try … thenthe first Glossary: Valuevalue is selected, Flow control: if … then Flow control: try … thenelse Flow control: if … then Flow control: try … thenthe second Glossary: Valuevalue is selected as Flow control: if … then Flow control: try … thenthe result of Flow control: if … then Flow control: try … thenthe operation. List functions: thisThis is similar to Flow control: if … thenif .. Flow control: if … then Flow control: try … thenelse .. Flow control: if … then Flow control: try … thenthen except that it happens inside an Vipsi command syntax: Expressions Glossary: Expressionexpression.
Flow control: if … then Flow control: if … thenIf the two Glossary: Valuevalues have different Data Types Invariants: Data typesdata types Flow control: if … then Flow control: try … thenthen Flow control: if … then Flow control: try … thenthe result has Flow control: if … then Flow control: try … thenthe type of Flow control: if … then Flow control: try … thenthe selected Glossary: Valuevalue.
Pruning: Depending on Flow control: if … then Flow control: try … thenthe Flow controlcondition either Flow control: if … then Flow control: try … thenthe first Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or second Glossary: Valuevalue is evaluated Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Flow control: if … then Flow control: try … thenthe other is skipped Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Operators: Bitwise Not "~" Operators: Boolean Negation "!"not executed Operators: Make Identifier "@"at all. Pruning is especially useful Flow control: if … thenif one Glossary: Operator Glossary: Operandoperand is only valid under certain Flow controlconditions Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and must Operators: Bitwise Not "~" Operators: Boolean Negation "!"not be executed otherwise.
Examples:
Instructions: putput a>b ? a : b
Instructions: putput 1 ? a : 347rz34834n
Instructions: putput Numeric functions: existsexists(a) ? a : 0
Instructions: putput Numeric functions: countcount(myList)>0 ? myList[1] : ""
a = Numeric functions: istextistext(a) ? "123" : 123
<value> = <condition> ? <condition> ? <value> : <value>
: <condition> ? <value> : <value>
Flow control: if … then Flow control: try … thenThe Operators: Select "? :"select operator may be nested without Separators: Round brackets "( … )" Functions with varying return types: bracket expression "()"parenthesis. List functions: thisThis is similar to Select "? :": Nestingnesting Flow control: if … thenif .. Flow control: if … then Flow control: try … thenelse .. Flow control: if … then Flow control: try … thenthen. Operators: Bitwise Not "~" Operators: Boolean Negation "!"Note: It is Operators: Bitwise Not "~" Operators: Boolean Negation "!"not possible to Text functions: replace Instructions: replacereplace a <condition> by a Operators: Select "? :"select operator Vipsi command syntax: Expressions Glossary: Expressionexpression without Separators: Round brackets "( … )" Functions with varying return types: bracket expression "()"parenthesis.
Example:
Instructions: var How does VScript::Value() work?: Var*&var errno_notrepresentable = 125;
Instructions: var How does VScript::Value() work?: Var*&var result_notrepresentable = 125;
Flow control: returnreturn
ErrNo()
? ErrNo() < errno_notrepresentable
? ErrNo()
: errno_notrepresentable
: Numeric functions: isnumberisnumber(result) && result<result_notrepresentable
? result
: result_notrepresentable;
<value> = <condition> ? <value>
: <condition> ? <value>
: <condition> ? <value>
: <value>
You can stack any Glossary: number, num_valnumber of alternative cases. List functions: thisThis is effectively done by continuously replacing Flow control: if … then Flow control: try … thenthe second <value> of a Operators: Select "? :"select operator Vipsi command syntax: Expressions Glossary: Expressionexpression by another Operators: Select "? :"select operator Vipsi command syntax: Expressions Glossary: Expressionexpression. Flow control: if … then Flow control: try … thenThe effect is similar to Flow control: if … thenif .. Flow control: if … thenelif .. Flow control: if … thenelif .. Flow control: if … then Flow control: try … thenelse .. Flow control: if … then Flow control: try … thenthen.
Example:
vipsi> Instructions: var How does VScript::Value() work?: Var*&var a=2
vipsi> Instructions: var How does VScript::Value() work?: Var*&var Z.Z
vipsi> Z.Z = a==1 ? "Foo" : a==2 ? "Schnerk" : a==4 ? "Schubi" : "Thor"
vipsi> Instructions: putput Z.Z Schnerk
vipsi>
In Flow control: if … then Flow control: try … thenthe above example "Foo", "Schubi" Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and "Thor" are skipped Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Operators: Bitwise Not "~" Operators: Boolean Negation "!"not executed due to pruning.
|