Download presentation
Presentation is loading. Please wait.
Published byPatrick Whitehead Modified over 9 years ago
2
1 © 2000 John Urrutia. All rights reserved. Qbasic Looping Statements & Formatted Output
3
2 © 2000 John Urrutia. All rights reserved. Here we go Loop de Loop A loop is a set of statements that are executed repeatedly. Types Controlled Pre-test Post-test Infinite
4
3 © 2000 John Urrutia. All rights reserved. Infinite Loops Generally a bad thing. Keeps going and going and … Going
5
4 © 2000 John Urrutia. All rights reserved. Controlled Loops Governed by a condition. Logical Sentinel Mathematical Counter Environmental EOF()
6
5 © 2000 John Urrutia. All rights reserved. Infinite DO…LOOP syntax DO statements LOOP Pre-Test { WHILE | UNTIL } condition Post-Test
7
6 © 2000 John Urrutia. All rights reserved. Condition A comparison of two or more things. The comparison will result in: TRUE state FALSE state
8
7 © 2000 John Urrutia. All rights reserved. DO WHILE…LOOP Statement Pretest loop If condition is true execute DO WHILE DAY$ = YES$ PRINT “Is it Night yet?” LOOP
9
8 © 2000 John Urrutia. All rights reserved. DO…LOOP UNTIL Statement Posttest loop Executes at least once DO PRINT “DO-WAH-DIDDY” LOOP UNTIL The.Cows = Come.Home
10
9 © 2000 John Urrutia. All rights reserved. Boolean or Logical Expressions Used in all conditions Algebra created by George Boole Always evaluates to a binary state Generally: 1 is TRUE 0 is FALSE
11
10 © 2000 John Urrutia. All rights reserved. Relational Expressions Single relational operator two operands <Less than >Greater than =Equal to <=Less than or equal to >=Greater than or equal to <>Not equal to
12
11 © 2000 John Urrutia. All rights reserved. Comparisons Numeric comparisons are simple. Compares bit for bit Negative numbers are stored in 2’s compliment +1 10 = 0000 16 = 0000 0000 000 00001 2 +0 10 = 0000 16 = 0000 0000 0000 0000 2 -1 10 = FFFF 16 = 1111 1111 1111 1111 2 -2 10 = FFFE 16 = 1111 1111 1111 1110 2 -3 10 = FFFD 16 = 1111 1111 1111 1101 2
13
12 © 2000 John Urrutia. All rights reserved. Comparisons Strings are based on the collating sequence (ASCII shown below) “1” char =48 10 =30 16 =0011 0000 2 “9” char =57 10 =39 16 =0011 1001 2 “A” char =65 10 =41 16 =0100 0001 2 “Z” char =90 10 =5A 16 =0101 1010 2 “a” char =97 10 =61 16 =0110 0001 2 “z” char =122 10 =7A 16 =0111 1010 2
14
13 © 2000 John Urrutia. All rights reserved. When is an “A” not an “a”? When comparing strings the case counts. Use the UCASE$() function to limit the number of options from your user.
15
14 © 2000 John Urrutia. All rights reserved. Compound Conditions When 2 or more expressions are combined together. Used to specify complex conditions in one statement.
16
15 © 2000 John Urrutia. All rights reserved. Boolean Operators NOT– negation (bit-wise complement) AND– logical addition (conjunction) OR– logical subtraction (disjunction) XOR– exclusive “or” EQV– logical equivalence IMP– logical implication
17
16 © 2000 John Urrutia. All rights reserved. NOT Boolean Truth Tables Expr NOT FalseTrue FalseTrue
18
17 © 2000 John Urrutia. All rights reserved. AND Boolean Truth Tables Expr 1Expr 2 AND True FalseTrue False TrueFalse
19
18 © 2000 John Urrutia. All rights reserved. OR Boolean Truth Tables True FalseTrue FalseTrue False Expr 1Expr 2 OR
20
19 © 2000 John Urrutia. All rights reserved. Nested Loops A loop within a loop ones% = 0 tens% = 0 DO WHILE tens% < 10 DO WHILE ones% < 10 PRINT tens% ; “-“ ; ones% ones% = ones% + 1 LOOP ones% = 0 tens% = tens% + 1 LOOP
21
20 © 2000 John Urrutia. All rights reserved. More Formatted Output TAB( n ) n – represents the column number to tab to SPC( n ) n – represents the number of spaces to insert
22
21 © 2000 John Urrutia. All rights reserved. TAB examples PRINT TAB(10); “10”; TAB(20); “20”; TAB(30); “30” 0000000001111111111222222222233333333334 1234567890123456789012345678901234567890 10 20 30
23
22 © 2000 John Urrutia. All rights reserved. SPC example PRINT SPC(10); “10”; SPC(10); “20”; SPC(10); “30” 0000000001111111111222222222233333333334 1234567890123456789012345678901234567890 10 20 30
24
23 © 2000 John Urrutia. All rights reserved. The PRINT USING statement Writes formatted data to the teminal PRINT USING “ format-string ” ; output-list The format-string specifies Numeric edited data formats String formats Literal data
25
24 © 2000 John Urrutia. All rights reserved. USING format characters Strings \n\ – first n +2 characters in the string ! – first character in the string & – no formatting _ – print character not format
26
25 © 2000 John Urrutia. All rights reserved. USING format characters Numbers # – number digit . – decimal point , – thousands separator + – sign of number - – trailing minus sign $ $$ – fixed / floating dollar sign
27
26 © 2000 John Urrutia. All rights reserved. PRINT USING example S PRINT USING “A=# and B=$#,###.##”; 5; 1234.56 A=5 and B=$1,234.56 PRINT USING “You’re a \ \ and I’m a & _!”; “nutria”; “foolish” You’re a nut and I’m a fool!
28
27 © 2000 John Urrutia. All rights reserved. Qbasic screen manipulation The LOCATE statement
29
28 © 2000 John Urrutia. All rights reserved. LOCATE LOCATE – position on screen row%, column% cursor% start% stop% CSRLIN – line cursor is on POS(0) – column cursor is on
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.