Lecture 5. AMES 5, Tues. 19 Jan. 1999

From the course outline we see the reading assignment this week is Chapter 4 on Program Control Statements. You need to turn in modified versions of all the example programs in this chapter, and do Practice Programs 4.1 and 4.2.

You have already seen some examples of branching and looping operations in programming, which occur when decisions are made based on logical expressions, and when repeated actions are required. Any computer program consists of sequential, loop, and branch structures. Chapter 4 focuses on loops and branches. Some of the concepts introduced are:

• Flow of program control: the DO and LOOP statements. The loop body. The control variable.
• Branching using the IF and ELSE statements.
• Relational operators: =, <>, <, >, <=, <=. Simple logical expressions, eg. sum=7 (not an assignment!).
• Compound logical expressions, eg. "if a=5 and b=7" may be true or false, and may control a branching statement in a computer program.
• Truth table: fill in X Y XandY XorY with Ts and Fs.
• DO LOOP with WHILE and UNTIL tests.
• The EXIT DO statement: a last resort. The ^. parachute from an infinite do loop.
• The FOR and NEXT loop. The initial limit value and the control variable.
• The STEP modifier. Looping with a negative step.
• Branching with the IF statement. The IF-then-ELSE-END IF structure.
• The ELSEIF-choice-then stucture.
• SELECT CASE expression CASE test1 CASE test2 CASE ELSE END SELECT statements.
• Reading values with READ and DATA statements. END #N and MORE #N tests.
• The RESTORE statement (See PP5.1).

All of these concepts are illustrated by the Example Programs which you will modify in your homework.

Final Project: You should have begun thinking about your final project. Write pseudo code statements at the beginning of the program to outline for yourself how you plan to proceed and to document for readers (and TAs) what its purpose is and how it is organized. Do this before you start putting in code, and revise as necessary if the code doesn't perform as you first expected.

Quiz 3a Solution

Lecture 6. AMES 5, Thurs. , Jan. 21, 1999

Work through and modify all the Example Programs of Chapter 4. Your modifications should illustrate an understanding of how the program works and what it is attempting to illustrate. Bring your questions about particular Example Programs to class if you want to see how I did it in my version of the homework. For example, here is my version of MEX5-15, from next week's homework. From this week's homework, see MEX04-14 about the SELECT CASE structure. Work as many unassigned Practice Programs as you can find time for, for example Practice Program PP4.3. You can select the text of the program from this webpage version and paste it into True Basic, although you will need to edit out the extra lines before it will run.

If you are working ahead, you might be interested in Practice Program PP5.3, where dates are entered into the program of PP5.2 by means of a DATA statement.

Logical variables such as more data and end data have values true or false depending on whether more data exists for reading or not. These variables are useful as control variables in do-loops reading from data statements, as shown in the example.

Use of select case, more data, end data, and graphical commands is illustrated in another example.

Quiz 3b (solution).

Help