scheme if else statements

First, it define a variable x and assign 11 to it.
Checks if x is less than 10, in which case is false, so it skip x, and go to the next argument which is another if statement.
The second if checks if the x is greater than 20, x is not, so it skip the first argument x and proceed to the second argument which is expression to multiply x by 2, and the result of the multiplication is the result of this program. It prints 22 since 11 times 2 is 22.
[code language=”text”]
(define x 11)
(if (< x 10)
x
(if (> x 20)
x
(* x 2)
)
)
[/code]

Output:
[code language=”text”]
;Loading "ifelse.scm"… done
;Value: 22
[/code]

Search within Codexpedia

Custom Search

Search the entire web

Custom Search