Смекни!
smekni.com

Conditional And Iterative Data Types Essay Research (стр. 2 из 2)

Scheme is the last and most unusual programming language of this paper. Scheme can implement both conditional and iterative structures, but the syntax of scheme is totally different from C++, Java, Pascal, Qbasic, or COBOL. The Scheme programming language is designed in a recursive manner. All Scheme programs are recursive and are actually iterative because the program iterates over and over again. The recursive nature of Scheme is not however an iterative structure. The conditional structures of Scheme us such keywords as if, else, case, and cond. The iterative structure of Scheme seems to only be seen with the keywords loop or do. Scheme conditional and iterative structures are seen below .

(if (* n 0) (case (+ x y)

(- 1 n)) ((1 3 5 7 9) ‘odd)

((0 2 4 6 8) ‘even)

——————————— ——————————————-

(cond (loop

(eqv? msg ‘empty?) (if (= n 0) (break ls))

(eqv? msg ‘push!) (set! ls (cons ‘a ls))

(else “oops”)) (set! n (- n 1)))

———————————- ——————————————–

(cond (do (( i 2 (+ i 1)))

(* x 0) ((*= i n))

(* x 0)

The syntax of the if block looks very different from any other languages in this paper, but it behaves in a similar fashion to other simple conditional structures. The if statement states that if ‘n’ is less than zero then subtract one from ‘n’. The cond with the else is a multi-alternative conditional structure. The first line asks if the variable ‘msg’ contains the string ‘empty?’. The second line asks if the variable ‘msg’ contains the string ‘push!’, and the else line says if neither of the previous two lines are true print ‘oops’. The cond block on the bottom is a two-alternative conditional structure. The first condition is if x is less than zero, and the second condition is if x is greater than zero. The case block is another multi-alternative conditional structure. If x plus y is equal to and odd number then ‘odd’ is printed, and if x plus y is equal to an even number then ‘even’ is printed. The loop code is a pretest iterative structure. ‘n’ is tested against zero for equality. If they are equal then the loop is stopped. The do block corresponds to the posttest iterative structure. The first line is executed until ‘i’ is greater than or equal to ‘n’, but the condition is not tested until the first line is executed at least once. Scheme is an odd language, but once it is mastered is can accomplish any programming task set forth.

Comparatively, the conditional and iterative structures in all the languages previously mentioned are very similar to one another. All of the simple conditional structures even use the same key word ‘if’. The conditionals in the languages all accomplish the same tasks only some languages use different methods. The iterative structures allow similar tasks to be completed by all languages as well. For the most part the iterative structures of all the languages use at least the keyword ‘do’ or perhaps ‘while’. The key words may vary but the function is all the same. The structures are used for iteration. The blocks of statements in the iterative loop must be performed time and time again. C++ and Java are the most similar languages when the conditional and iterative structures are compared. The two languages that are the most dissimilar are COBOL and Scheme. COBOL is lengthy with a few control structures. Scheme is compact with many control structures. When comparing the control structures of C++, Java, Pascal, Qbasic, COBOL, and Scheme, no one language can be said to be better than any of the others.

Dershem, Herbert L., and Jipping, Michael J. 1995. Programming Languages Structures and Models. Boston, MA: PWS Publishing Company.

Deitel, H., M., Deitel, P., J. 1998.C++ How To Program. Upper Saddle River, NJ: Prentice-Hall.

Flanagan, David. 1997. Java In a Nutshell. Sebastopol, CA: O’Reilly & Associates.

Calvert, Charles. 1993. Turbo Pascal Programming 101. Carmel, IN: Sams Publishing.

Perry, Greg. 1993. Qbasic by Example. Indianapolis, IN: Que

Wessler, Jon, et al. 1998. COBOL Unleashed. Carmel, IN: Sams Publishing.

Dybvig, Kent, R. 1996. The Scheme Programming Language. Upper Saddle River, NJ: Prentice-Hall.