Conditional and Iterative
A programming language cannot be a programming language with out its conditional and iterative structures. Programming languages are built to accomplish the task of controlling computer input and output. A programmer must use every tool available to complete his/her given tasks, and conditional as well as iterative statements are the most basic items of programming which must be mastered. Many different programming languages can demonstrate conditional and iterative statements including C++, Java, Pascal, Qbasic, COBOL, and Scheme. Most of these languages implement conditional and iterative statements in a similar fashion; however, there are a few differences.
The conditional structure is easy to understand and self-defining. The whole statement is base on a condition and its veracity. When the statement or "test" is found to be true, a statement is executed, and if it is false, another test is given or the program continues to the next block. Conditional structures include the simple, two-alternative, multi-alternative, and non-deterministic conditional. The simple conditional is the easiest to understand being the IF-THEN statement.
IF a condition is met THEN execute a statement. The two-alternative conditional or IF-ELSE is also easy to understand.
IF a condition is met execute a statement; ELSE the condition was not met so execute a different statement. The multi-alternative conditional is very close to the two-alternative conditional.
The IF question is asked about a statement, and if it is not true, the next statement is examined. If statement number two is not true, the next statement is examined; then the next statement is examined and so forth until a condition is met, and the control is carried out of the multi-alternative conditional. The non-deterministic conditional is similar to the multi-alternative conditional, because it has multiple conditionals.
The reason multi-alternative and non-deterministic conditionals are different, stems from the release of program's control or flow. The non-deterministic conditional tests each statement to see if its condition is met; whereas the multi-alternative conditional only tests statements until one of the conditions is met. After one of the conditions is met, the multi-alternative conditional releases the program control and fails to check anymore statements.
The iterative structure is a bit more complicated than the conditional structure, but it is easy to understand. An iterative structure consists of a block of statements that are executed repetitively. They might be executed once or a hundred times depending on the controls placed on the structure. Iterative structures include non-terminating, pretest, posttest, in-test, fixed-count, and non-deterministic iteration. The non-terminating iterative structure is not very common, because once it has program control, it does not release its control until the whole program is terminated.
Once a non-terminating iterative structure is activated it continues to run forever. The pretest iterative structure tests a condition first, then if it is true, the following statements are executed repeatedly - testing the statement each loop - until the statement is false.
Once the statement is found to be false, control is returned to the program ending the...
Please join StudyMode to read the full document