Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright 1999 by Larry Fuhrer. Pascal Programming Branching, Loops, Predefined Functions.

Similar presentations


Presentation on theme: "Copyright 1999 by Larry Fuhrer. Pascal Programming Branching, Loops, Predefined Functions."— Presentation transcript:

1

2 Copyright 1999 by Larry Fuhrer. Pascal Programming Branching, Loops, Predefined Functions

3 Copyright 1999 by Larry Fuhrer. Pascal Programming The if-then-else statement – a branching method Chooses between two alternative courses of action Syntax: if expression1 operator expression2 then statement1 else statement2 Operators: = equal to; <> not equal to; greater than; = greater than or equal to.

4 Copyright 1999 by Larry Fuhrer. Pascal Programming Note – the if-then-else does not place a semi-colon (;) at the end of the then statement... In Turbo Pascal upper case X and lower case x are not the same character! REAL does not have an exact value... therefore testing the equal = or not equal <> has little value.

5 Copyright 1999 by Larry Fuhrer. Pascal Programming Syntax...rules describing how to write, punctuate statements, declaration and other language constructs. Syntax rules are RIGID... You need a precise description of the syntax or grammar as you write.

6 Copyright 1999 by Larry Fuhrer. Pascal Programming Compound Statement A compound statement acts as a single statement e g: (ignore my outline marks) –begin writeln (‘You pass with a score of ‘); writeln (Score – 60, ‘points to spare. ‘) –end

7 Copyright 1999 by Larry Fuhrer. Pascal Programming While do statements – a looping method A loop repeats statement or group of statements –e g: while Number > 0 do –While the number is greater than zero continue to do the following... Syntax: while expression1 operator expression2 do body Each time through the loop is an interation A while statement must be initialized –e g: Number := 0

8 Copyright 1999 by Larry Fuhrer. Pascal Programming Predefined Functions... Pascal includes predefined functions. Sqrt or square root is one example The function requires an argument. –e g: sqrt (4) {the argument is 4} The function may be included in a formula. Continue...

9 Copyright 1999 by Larry Fuhrer. Pascal Programming Predefined functions continued... ln computes the natural logarithm There is no exponential operator in Pascal

10 Copyright 1999 by Larry Fuhrer. Pascal Programming Iterative enhancement – create a simple program and then add features and refinement to make it more powerful. Run-time errors appear when the program is run. They seem to be hidden when you debug the program. Overflow errors arise when numbers get too small or too large. With logical errors, the program will run but not produce intended results.


Download ppt "Copyright 1999 by Larry Fuhrer. Pascal Programming Branching, Loops, Predefined Functions."

Similar presentations


Ads by Google