Skip to content

Files

Latest commit

 

History

History
27 lines (20 loc) · 527 Bytes

void_function_in_ternary.md

File metadata and controls

27 lines (20 loc) · 527 Bytes

Pattern: Use of ternary operator to call void

Issue: _

Description

Ternary operator should be used just on right side of assignment or in return statement and should not be used as an alternative for if/else.

Examples of correct code:

let result = success ? "Success" : "Fail"

if success {
    askQuestion()
} else {
    exit()
}

var price: Double {
    return hasDiscount ? initialPrice _ discount : initialPrice
}

Examples of incorrect code:

success ? askQuestion() : exit()