1 © 2000 John Urrutia. All rights reserved. Qbasic Looping Statements & Formatted Output.

Slides:



Advertisements
Similar presentations
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Advertisements

5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Flow of Control (1) : Logic Clark Savage Turner, J.D., Ph.D. Some lecture slides have been adapted from those developed.
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
JavaScript, Fourth Edition
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
JavaScript, Third Edition
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6: Repetition  Some additional operators increment and decrement.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
The switch Statement, DecimalFormat, and Introduction to Looping
Fundamentals of Python: From First Programs Through Data Structures
Chapter 5 new The Do…Loop Statement
Spreadsheets Objective 6.02
Fundamentals of Python: First Programs
Computers Organization & Assembly Language
CIS Computer Programming Logic
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
UniMAP Sem2-08/09 DKT121: Fundamental of Computer Programming1 Introduction to C – Part 2.
2440: 211 Interactive Web Programming Expressions & Operators.
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
Java Software Solutions Lewis and Loftus Chapter 5 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. More Programming Constructs.
Basic Operators. What is an operator? using expression is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
1 © 2001 John Urrutia. All rights reserved. Chapter 10 using the Bourne Again Shell.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
Islamic University Of Gaza, Nael Aburas Data Storage Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas
1 © 2000 John Urrutia. All rights reserved. Qbasic Input, Calculations and Functions.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Week 8: Decisions Bryan Burlingame 21 October 2015.
Thinking Mathematically
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Control statements Mostafa Abdallah
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition.
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
Chapter 3 Selection Statements
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
CprE 185: Intro to Problem Solving (using C)
Chapter 5- part 2 Control Statements: Loops 2
Building Java Programs Chapter 2
Chapter 2 Programming Basics.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Data Types and Expressions
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

1 © 2000 John Urrutia. All rights reserved. Qbasic Looping Statements & Formatted Output

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

3 © 2000 John Urrutia. All rights reserved. Infinite Loops Generally a bad thing. Keeps going and going and … Going

4 © 2000 John Urrutia. All rights reserved. Controlled Loops Governed by a condition.  Logical  Sentinel  Mathematical  Counter  Environmental  EOF()

5 © 2000 John Urrutia. All rights reserved. Infinite DO…LOOP syntax DO statements LOOP Pre-Test { WHILE | UNTIL } condition Post-Test

6 © 2000 John Urrutia. All rights reserved. Condition A comparison of two or more things. The comparison will result in:  TRUE state  FALSE state

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

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

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

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

11 © 2000 John Urrutia. All rights reserved. Comparisons Numeric comparisons are simple.  Compares bit for bit  Negative numbers are stored in 2’s compliment  = =  = =  = FFFF 16 =  = FFFE 16 =  = FFFD 16 =

12 © 2000 John Urrutia. All rights reserved. Comparisons Strings are based on the collating sequence (ASCII shown below)  “1” char =48 10 =30 16 =  “9” char =57 10 =39 16 =  “A” char =65 10 =41 16 =  “Z” char =90 10 =5A 16 =  “a” char =97 10 =61 16 =  “z” char = =7A 16 =

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.

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.

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

16 © 2000 John Urrutia. All rights reserved. NOT Boolean Truth Tables Expr NOT FalseTrue FalseTrue

17 © 2000 John Urrutia. All rights reserved. AND Boolean Truth Tables Expr 1Expr 2 AND True FalseTrue False TrueFalse

18 © 2000 John Urrutia. All rights reserved. OR Boolean Truth Tables True FalseTrue FalseTrue False Expr 1Expr 2 OR

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

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

21 © 2000 John Urrutia. All rights reserved. TAB examples PRINT TAB(10); “10”; TAB(20); “20”; TAB(30); “30”

22 © 2000 John Urrutia. All rights reserved. SPC example PRINT SPC(10); “10”; SPC(10); “20”; SPC(10); “30”

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

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

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

26 © 2000 John Urrutia. All rights reserved. PRINT USING example S PRINT USING “A=# and B=$#,###.##”; 5; A=5 and B=$1, PRINT USING “You’re a \ \ and I’m a & _!”; “nutria”; “foolish” You’re a nut and I’m a fool!

27 © 2000 John Urrutia. All rights reserved. Qbasic screen manipulation The LOCATE statement

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