Josh
Josh

Reputation: 519

conditional statements in racket

(define (number n)
(cond
  [(< n 10) 5.0] 
  [(< n 20) 5] 
  [(< n 30) true]))

How would I add an else statement at the end?

[else false])

Thanks.

Upvotes: 2

Views: 672

Answers (1)

&#211;scar L&#243;pez
&#211;scar L&#243;pez

Reputation: 235994

Like this:

(define (number n)
  (cond
    [(< n 10) 5.0] 
    [(< n 20) 5] 
    [(< n 30) true]
    [else false]))

Just remember - the else clause (if present) must be the last clause in a cond form. If it was not explicitly written and none of the conditions hold, then #<void> is returned.

Upvotes: 2

Related Questions