1 / 28

Qbasic

Qbasic. Looping Statements & Formatted Output. Here we go Loop de Loop. A loop is a set of statements that are executed repeatedly. Types Controlled Pre-test Post-test Infinite. Infinite Loops. Generally a bad thing. Keeps going and going and …. Going. Going. Going. Going. Going.

Download Presentation

Qbasic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Qbasic Looping Statements & Formatted Output

  2. Here we go Loop de Loop • A loop is a set of statements that are executed repeatedly. • Types • Controlled • Pre-test • Post-test • Infinite

  3. Infinite Loops • Generally a bad thing. • Keeps going and going and … Going Going Going Going Going Going Going Going Going

  4. Controlled Loops • Governed by a condition. • Logical • Sentinel • Mathematical • Counter • Environmental • EOF()

  5. DO…LOOP syntax Post-Test Pre-Test Infinite DO statements LOOP { WHILE | UNTIL } condition { WHILE | UNTIL } condition

  6. Condition • A comparison of two or more things. • The comparison will result in: • TRUE state • FALSE state

  7. DO WHILE…LOOP Statement • Pretest loop • If condition is true execute DO WHILE DAY$ = YES$ PRINT “Is it Night yet?” LOOP

  8. DO…LOOP UNTIL Statement • Posttest loop • Executes at least once DO PRINT “DO-WAH-DIDDY” LOOP UNTIL The.Cows = Come.Home

  9. 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

  10. 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

  11. Comparisons • Numeric comparisons are simple. • Compares bit for bit • Negative numbers are stored in 2’s compliment • +110 = 000016 = 00000000 000000012 • +010 = 000016 = 00000000 000000002 • -110 = FFFF16 = 11111111 111111112 • -210 = FFFE16 = 11111111 111111102 • -310 = FFFD16 = 11111111 111111012

  12. Comparisons • Strings are based on the collating sequence (ASCII shown below) • “1”char =4810 =3016 =001100002 • “9”char =5710 =3916 =001110012 • “A”char =6510 =4116 =010000012 • “Z”char =9010 =5A16 =010110102 • “a”char =9710 =6116 =011000012 • “z”char =12210 =7A16 =011110102

  13. 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.

  14. Compound Conditions • When 2 or more expressions are combined together. • Used to specify complex conditions in one statement.

  15. Boolean Operators • NOT – negation (bit-wise complement) • AND – logical addition (conjunction) • OR – logical subtraction (disjunction) • XOR – exclusive “or” • EQV – logical equivalence • IMP – logical implication

  16. NOT Boolean Truth Tables NOT True False False True

  17. AND Boolean Truth Tables AND True True True False True False False True False False False False

  18. OR Boolean Truth Tables OR True True True True True False False True True False False False

  19. Nested Loops • A loop within a loop ones% = 0tens% = 0 DO WHILE tens% < 10 DO WHILE ones% < 10 PRINT tens% ; “-“ ; ones% ones% = ones% + 1 LOOP ones% = 0 tens% = tens% + 1LOOP

  20. More Formatted Output • TAB(n) • n – represents the column number to tab to • SPC(n) • n – represents the number of spaces to insert

  21. TAB examples PRINT TAB(10); “10”; TAB(20); “20”; TAB(30); “30” 00000000011111111112222222222333333333341234567890123456789012345678901234567890 10 20 30

  22. SPC example PRINT SPC(10); “10”; SPC(10); “20”; SPC(10); “30” 00000000011111111112222222222333333333341234567890123456789012345678901234567890 10 20 30

  23. 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

  24. USING format characters • Strings • \n\ – first n +2 characters in the string • ! – first character in the string • & – no formatting • _ – print character not format

  25. USING format characters • Numbers • # – numberdigit • . – decimal point • , – thousands separator • + – sign of number • - – trailing minus sign • $ $$ – fixed / floating dollar sign

  26. PRINT USING exampleS 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!

  27. Qbasicscreen manipulation The LOCATE statement

  28. LOCATE • LOCATE – position on screen • row% , column% • cursor% • start% • stop% • CSRLIN – line cursor is on • POS(0) – column cursor is on

More Related