Jess71p2 23 - while is a boolean expression. The while...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
3. Jess Language Basics 15 Jess> ?*x* 4 You can read about the set-reset-globals and the accompanying get-reset-globals function in the Jess function guide. 3.8. Control flow In Java, control flow -- branching and looping, exception handling, etc -- is handled by special syntax and keywords like if , while , for , and try . In Jess, as we said before, everything is a function call, and control flow is no exception. Therefore, Jess includes functions named if , while , for , and try , along with others like foreach . Each of these functions works similarly to the Java construct of the same name. 3.8.1. A simple loop For example, a Jess "while" loop looks like this: Jess> (bind ?i 3) 3 Jess> (while (> ?i 0) (printout t ?i crlf) (-- ?i)) 3 2 1 FALSE The first argument to
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: while is a boolean expression. The while function evaluates its first argument and, if it is true, evaluates all its other arguments. It repeats this procedure until the first argument evaluates to FALSE ; a while loop always returns FALSE. There are several other looping functions built into Jess; see the descriptions of for and foreach in the Jess function index. There is also a break function that can be used to abort loops as well as return early from the right-hand-side of a rule. 3.8.2. Decisions and branching The if function looks like this: Jess> (bind ?x 1) 1 Jess> (if (> ?x 100) then (printout t "X is big" crlf) elif (> ?x 50) then (printout t "X is medium" crlf) else (printout t "X is small" crlf))...
View Full Document

This note was uploaded on 03/02/2010 for the course COMP 102 taught by Professor Smith during the Spring '10 term at California State University , Monterey Bay.

Ask a homework question - tutors are online