0

While searching on the web I came across this page the user has created multiple examples of solidity smart contract

On multiple payout deed smart contract I can't understand this line duePayouts = duePayouts + paidPayouts > PAYOUTS ? PAYOUTS - paidPayouts : duePayouts;

This is the link to example

If you can please explain how that line works and what are those operators ':' and '?'

Thanks

0

That part of code is called "conditional operator" and is mostly used in C++. It is same as this code:

if( duePayouts + paidPayouts > PAYOUTS ){
    duePayouts = PAYOUTS - paidPayouts;
}else{
    duePayouts = duePayouts;
}

The "?" is like "if" and ":" is like "else".

It's Format is like this: conditional Expression ? expression1 : expression2;

if the conditional Expression is true, expression1 executes, otherwise if the conditional Expression is false, expression 2 executes.

0

Ternary operator:

<conditional> ? <if-true> : <if-false>

The code in the example can be interpreted as:

if (duePayouts + paidPayouts > PAYOUTS) {
  duePayouts = PAYOUTS - paidPayouts;
} else {
    // NOTE: In that case we can just skip section 'else'
    duePayouts = duePayouts;
}  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.