The Fortran Basics. Handout Two February 10, 2006

Size: px
Start display at page:

Download "The Fortran Basics. Handout Two February 10, 2006"

Transcription

1 The Fortran Basics Handout Two February 10, 2006 A Fortran program consists of a sequential list of Fortran statements and constructs. A statement can be seen a continuous line of code, like b=a*a*a or INTEGER :: a,b. A construct is a group of statements that together form a specific task and are defined by the Fortran language. You will learn some Fortran constructs later in these notes. When defining the syntax of a Fortran statement or construct, in these notes, the following will be used Anything inside curly brackets, { }, will be a Fortran keyword. Anything inside angular brackets, <>, is the choice of the programmer Anything inside square brackets, [ ], will be optional to the statement. 1 Program Structure When you are writing a Fortran program you must be careful to adhere to the required structure of a Fortran program. Each program unit must have this structure. A program unit can be the main program, a subroutine, function or a module. So far you have only been introduced to the main program unit, so for now do not worry about the others. The required structure is explained with the help of your power3.f90 code, 1. PROGRAM power3 2.!*** program to calculate 3rd power of IMPLICIT NONE INTEGER :: a, b a = 5 9. b = a*a*a PRINT*, a,b END PROGRAM power3 1. The program unit header statement must come first, for example PROGRAM <program name> Line 1 in the power3 code. 2. Next follows the specification region, in this region you put any external references, data type declarations, interface blocks and the IMPLICIT NONE statement. Don t worry about the items listed in the above sentence that you have not met yet they will be explained later when required. Lines 4 6 in the power3 code. 1

2 3. Next follows the execution statements that follow the logical order of whatever you are trying to do. Lines 8 11 in the power3 code. 4. Finally the END statement to tell the compiler that there are no more lines to compile. For example END PROGRAM <program name> Line 13 in the power3 code. 2 Intrinsic Data Types and IMPLICIT NONE You have already seen the keyword INTEGER used in the power3 code you wrote earlier. It was used to declare variables of integer type. Fortran has five intrinsic data types. The word intrinsic means that they are defined within the Fortran language standard. The five data types are; INTEGER: For exact whole numbers. REAL (and DOUBLE PRECISION): For real numbers, variables declared as DOUBLE PRECISION will be more accurate than REAL variables. COMPLEX: For complex numbers of the form x+i y. CHARACTER: For characters and strings of characters. LOGICAL: For variables that have two possible values,.true. or.false.. For this course ALL data types you use in your code must be declared before you use them. To insure this is done ALL of you codes must contain the IMPLICIT NONE statement at the beginning of each program you write and as you will see later in the course it must be defined in other sections of code where necessary. 2.1 Numeric declarations (REAL,INTEGER & COMPLEX) The syntax of numeric declarations are of the form; {type}[,{attribute-list}] [::] variable[=<value>][,variable [=<value>],...] The type is of course one of the data types INTEGER, REAL... The attribute-list is an optional set of keywords that can alter the nature of a variable being declared, their are many attributes that can be given and they will be dealt with as we need them. So for example the following are valid examples of numeric variable declarations. NOTE how the :: is identified as being optional, however if there is a attribute-list OR a variable is being assigned an initial value then the :: is mandatory. I recommend that you use the :: in all your declarations as it does no harm and improves readability of your code. REAL :: angle INTEGER :: i,j,start=1 INTEGER :: a,b,c DOUBLE PRECISION :: acc COMPLEX :: plane INTEGER, PARAMETER :: dozen=12 REAL, PARAMETER :: pi= NOTE: The last declaration, in the above list, is an example of a variable being defined with an attribute. The PARAMETER attribute dictates that a constant is being defined. This means you can never change 2

3 its value, later in your code, from the one it is given during its declaration. If you do try to assign a value to data type declared with the attribute PARAMETER the compiler will flag an error causing compilation to fail. This is useful for any of your own constants and also common constants for example π. 2.2 Numeric Operators All the standard numeric operators exist in Fortran. Operators act on operands. Some have one operand and are termed monadic and some have two and are termed dyadic. Here is a table of the common Fortran numeric operators, they are numbered in order of precedence [1] being highest and at the top. [1] ** : Exponentiation operator, dyadic [2] / : Division operator, dyadic [2] * : Multiplicative operator, dyadic [3] - : minus operator monadic for negation [4] + : additive operator, dyadic [4] - : minus operator, dyadic If you are building a complicated expression you can use parentheses to change the default order that sub-expressions are evaluated making sure that they are being evaluated in the order you require. Example Consider the following expression, 8.0/4.0*3.0=6.0 : There is some confusion here as * and / have the same order of precedence, so which will Fortran evaluate first? When this occurs Fortran will operate a left to right rule so the left most expression in the conflict will be evaluated first. So 8.0/4.0 is calculated and then the result is multiplied by 3.0. To have Fortran calculate first 4.0*3.0 and divide the result into 8.0 you could make use of parenthesis and write 8.0/(4.0*3.0)= This left to right rule however does not apply to exponentiation. For example a**b**c, in this case a right to left rule is used to dictate the order of evaluation. 2.3 Character declarations (CHARACTER) The syntax of character declarations are of the form; CHARACTER [(LEN=<length>)][,{attribute-list}] [::] variable[=<value>][,variable[=<value>],...] This is similar to the numerical declaration, however, there is now an option (LEN=<length >) specifier. This length specifier allows the declaration of a character variable of more than one character. Consider the following character declarations. CHARACTER :: char1,char2,letter="i" CHARACTER, PARAMETER :: a="a",b="b",c="c" CHARACTER (LEN=6) :: class1="mt3501", class2="mt3502",class3="mt3503" CHARACTER (LEN=*), PARAMETER :: news1="man United will win the league!" CHARACTER (LEN=*), PARAMETER :: news2="scotland will win the next world cup!" NOTE: The last declaration has an * as its length specifier. This is because PARAMETER (only) declarations can have their length assumed by the compiler, so you do not have to state it for this case. 3

4 2.4 Logical declarations (LOGICAL) The syntax of numeric declarations are of the form; LOGICAL[,{attribute-list}] [::] variable[=<value>][,variable [=<value>],...] Some examples of logical type declarations. LOGICAL :: switch, gate LOGICAL :: ans1=.true. ans2=.false. NOTE: The logical type can have only two values,.true. or.false Valid variable names Notice that power3.f90 uses the variable names a and b. This raises the question what are valid variable names? A Fortran 90 name can have up to 31 characters. This can be any combination of letters (upper case or lower case), the ten digits 0-9 and the underscore character ; the first character must be a letter. Unlike UNIX, which is CASE sensitive, Fortran treats upper and lower case letters as identical. However I recommend that you always use the convention that variables you define are always lower case while Fortran key words (such as PROGRAM and REAL ) are in upper case. This makes it easier for people, including you, to read your programs. 3 Programing Style Always comment your code so you can understand it later and so others can make sense of it if they have to read it (including those who have to mark your work). Remember a comment is any text on a line following a!. Remember that comments are ignored by the compiler. Any Fortran 90 keywords and intrinsic functions such as SIN, COS and TAN should be in UPPER CASE letters and user created entities such as variable names should be in lower case. Indentation, this is essential for program readability. An indentation of two spaces should be applied program unit bodies and any statements inside fortran constructs should be indented a further two spaces. This will become clearer as you see example codes in the notes. Always use IMPLICIT NONE You should always choose the names of your data types (REAL, INTEGER etc.) so that they reflect their purpose in the code. For example you could call a constant π in your code pi. 4 Decision Making :: The IF Statement and Construct Decision making is an essential and powerful component of programing. 4.1 The If Statement One of the most common and simplest form of decision commands in Fortran is the IF statement. It takes the general form, IF (<logical expression>) <statement> A logical expression always reduces to either.true. or.false.. It is rather useless but the most 4

5 basic form of a logical expression would be simply the two logical constants.true. and.false., for example IF (.TRUE.) PRINT*,"Hello From Me" This statement will always of course print Hello From Me because.true. can only ever reduce to itself.true Relational Operators, Logical Operators & Logical Expressions Relational Operators Relational operators are used to test the relationship between two numeric operands for that specific operator. The relational operators are, < or.lt. : less than > or.gt. : greater than == or.eq. : identically equal to /= or.ne. : not equal to <= or.le. : less than or equal to >= or.ge. : greater than or equal to as mentioned above any expression involving these operators will reduce down to either.true. or.false.. Logical Operators Logical operators act on logical expressions to create a larger logical expression. The Fortran logical operators are listed in the table below and are in order of precedence, given in square brackets, from the top to the bottom. [1].NOT. : Negate the following operand [2].AND. :.TRUE. if both operands are.true. [3].OR. :.TRUE. if at least one operand is.true. [4].EQV. :.TRUE. if both operands reduce to the same [4].NEQV. :.TRUE. if both operands are different The order of precedence is important when dealing with logical expressions, however you can change 5

6 the order in which sub-expressions are evaluated by making use of parenthesis. Consider, Exercise One (I): Work out the values of ans1, ans2 and ans3. Check them by writing a small code and printing them out to screen using the fortran PRINT command. Create a handout2 directory and in it create a exercise1 directory. Write your code in the exercise1 directory and call it logical test.f90. Remember to compile use the command f90 -o logical test logical test.f90. LOGICAL :: tst1=.true., tst2=.true., tst3=.false. LOGICAL :: ans1,ans2,ans3 ans1=tst1.or. tst2.and. tst3 ans2=(tst1.or. tst2).and. tst3 ans3=tst1.or. (tst2.and. tst3) PRINT*, ans1,ans2,ans3 NOTE : In the ans1 expression the tst2.and. tst3 sub-expression is evaluated first! Now try the following exercise that uses logical expressions that involve both relational operators and logical operators. Exercise One (II): Work out the values of test1, test2 and test3. Check them by writing a small code and printing them out to screen. Do this in the exercise1 directory but write the code in a new file called logical test2.f90. REAL INTEGER LOGICAL LOGICAL :: height=1.85, weight=95.0 :: age=55 :: drinker=.true., employed=.true., smoker=.true. :: test1,test2,test3 If (age>50) Print*,"Over fifty" test1 = employed.and. (age<45) test2 = smoker.and. drinker.and. (height<2.00) test3 = (.NOT. smoker.or. (age<=55).and. (weight>50)).and. (height<=1.84) PRINT*,test1,test2,test3 6

7 4.3 The If Construct The IF construct is more flexible than the single IF statement. The IF construct can be seen as having three forms Form One The IF construct in its most simple form is IF (<condition>) THEN < statement 1> < statement 2> < etc > This form simply performs a single test and if the test result is true then a series (or a single) Fortran statements that lie in the body of the construct are executed. Form Two IF (<condition>) THEN <statements if condition is true> ELSE <statements if condition is false> This second form of the construct allows the program to take action on a series of Fortran statements if the the condition is false as well as if it is true. This is done by the addition of the ELSE keyword. Form Three IF (<condition1>) THEN <statements if condition1 is true> ELSEIF (<condition2>) THEN <statements if condition2 is true> ELSEIF (<condition3>) THEN <statements if condition3 is true> ELSEIF (<condition4>) THEN <statements if condition4 is true> ELSE <statements all conditions are false> The final form of the IF construct allows the programmer to produce a mutually exclusive list of options. NOTE there can be any number of ELSEIF branches in the construct. Also NOTE that the 7

8 ELSE is optional. Exercise Two: Create an exercise2 directory and in it write a program to calculate a the roots of a quadratic equation y = ax 2 + bx + c. Make use of the IF construct to categorise the quadratic into two real roots, one repeated real root, complex roots or no roots at all (ie. it is not a valid quadratic). To categorise the quadratic you will have to calculate the value of the discriminent b**2-4*a*c. Output the root(s) to the screen. Also calculate where the the quadratic has a turning point and the nature of this turning point and print these out to the screen. This is your first, in this course, real attempt at a meaningful Fortran code so it may seem a little daunting but spend some time thinking about how you are going to approach the problem. It can help to write down your ideas on paper first! Remember the roots of a quadratic are given by, b + b 2 4ac & b b 2 4ac. 2a 2a NOTE : For this exercise do NOT use the data type COMPLEX. You can solve the quadratic using only the REAL data type for all three cases of roots. As this is your first real attempt at a piece of code much of the code is given below. You are advised to make use of this and fill in the bits of missing code indicated by ****. PROGRAM quad!## Program to investigate a quadratic equation (y=a*x*x+b*x+c) IMPLICIT NONE!## Force explicit declaration of all variables!## Declare required variables **** IF (check) THEN! check must be.true. if "a" does not equal zero **** IF (discrim > 0) THEN!** If real solutions exist then enter construct **** ELSEIF (discrim == 0) THEN **** ELSE **** ELSE PRINT*,"This is not a valid quadratic" IF (check) THEN!## Calculate the quadratics turning point **** IF (a.lt. 0) THEN PRINT*,"Turning point is a maximum" ELSE PRINT*,"Turning point is a minimum" 8

9 5 Looping :: The DO Construct Computers are very powerful when dealing with repetitive tasks. To allow the programmer to implement this Fortran has a construct called the DO loop. It has a few different forms; 5.1 The Indexed DO Construct One form of looping in Fortran is the Indexed DO construct which has the form. DO <loop variable>=<expr1>,<expr2>[,<expr3>] <body statements> The loop variable runs from expression one in increments of expression three until it reaches the value expression two and then the loop terminates. Note that the three expressions could all be simply integer numbers. If the optional stride of the loop (<expr3>) is omitted then a stride of one is assumed. For example you should now calculate the 3rd power of all integers up to 8. This can be achieved by using a DO loop. Exercise Three In an exercise3 directory type the following code and save it as power3 loop.f90 compile and run it. PROGRAM power3_loop!*** 3rd power of a for 1 <= a <= 8 IMPLICIT NONE INTEGER :: a, b DO a = 1, 8 b = a*a*a PRINT*,a,"to the power of three = ",b END PROGRAM power3_loop The line DO a = 1, 8 tells the computer to repeat the section of the program between this line and the line. The part a = 1, 8 means that this section of code is to be repeated for a = 1, a = 2, a = 3... a = 8. Run the program and make sure that it works. NOTE that the indentation used inside the DO loop makes it easy to see where it starts and ends. 9

10 Exercise Four In an exercise4 directory copy your power3 loop.f90 from exercise three changing its name to factorial.f90 in the copying process. Edit it to create a code that will calculate the factorial value of the first eight integers and print them out to screen. The copy command you should use is below. fortran1 exercise4> cp../exercise3/power3 loop.f90 factorial.f The Conditional DO Loop Construct It is useful to have a looping construct that allows termination of the loop only when a certain condition has been met. For this situation Fortran has the DO - looping construct. DO <statement body> IF (<logical expression>) EXIT <statement body> The logic of this style is that the <statement body> is iterated through many times until the <logical expression> is true. 5.3 The DO WHILE Construct Fortran has the DO WHILE looping construct that does a very similar job to the conditional DO loop construct above. You should NOT use this DO WHILE form as the above conditional DO loop construct is more general and it is clear where the loop exits. The DO WHILE loop always exits at the top of the loop construct as this is where the test takes place. It is presented in these notes as you may well see it in some older codes. DO WHILE <condition> <body statements> The logic of this style is that the <statement body> is iterated through many times until the <condition> is true. 10

11 5.4 Nesting Do Loops It is often useful to nest Do loops. DO i=1,10 DO j=1,50 <body statements> Exercise Five In an exercise5 directory write a code that sums up 10*( )+11*( )...+19*( ) use two nested DO loops to do the calculation that iterate over and 20 29! 6 Numeric Arrays : Part One Arrays can be declared in Fortran and are in fact one of the most powerful features of the Fortran 90 language. A one dimensional numeric array is simply a list of numbers and could be used, for example, to represent a vector. A two dimensional array could be used to represent a matrix. Arrays for a given numeric data type are declared using the attribute DIMENSION(<array size>) in the attribute list of a numeric declaration statement. To declare an INTEGER array of one dimension, called intlist to hold thirty values use, INTEGER, DIMENSION(30) :: intlist!** 1D array to create a two dimensional array of real numbers with four elements in each extent of the array use, REAL, DIMENSION(4,4) :: mat1!** 2D array For example the factorial program could save the answers into an array. PROGRAM factorial IMPLICIT NONE REAL, DIMENSION(20) :: fact INTEGER :: n, nmax = 20!** set the first value fact(1) = 1.0!** calculate factorials DO n = 2, nmax fact(n) = fact(n-1) * REAL(n) PRINT*,fact END PROGRAM factorial 11

12 6.1 Printing Arrays to the screen You have seen how to print integers, reals etc. to the screen using the PRINT statement. If mat1 was a two dimensional array of real numbers representing a matrix then the command, PRINT*,mat1 would just print out all the elements of the matrix in a messy list to the screen. To print out the matrix in a structured form use the print statements PRINT*,mat1(1,:)!** Row one PRINT*,mat1(2,:)!** Row two PRINT*,mat1(3,:)!** Row three PRINT*,mat1(4,:)!** Row four This works because in the code mat1(1,:), the brackets have two arguments in them the 1 st is the number 1 and means reference only row one (the first dimension of the array), the 2 nd argument is a colon (:). The colon means reference EVERY element in the column (the second dimension of the array). Exercise Six : Write a program to create a two dimensional array with four elements in each dimension to represent a matrix. Set each of the matrix elements to be equal to the sum of its row index plus twice its column index. Hint: use a nested DO loop. Print out the matrix to the screen 12

Our Strategy for Learning Fortran 90

Our Strategy for Learning Fortran 90 Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data

More information

Data Types and Basic Calculation

Data Types and Basic Calculation Data Types and Basic Calculation Intrinsic Data Types Fortran supports five intrinsic data types: 1. INTEGER for exact whole numbers e.g., 1, 100, 534, -18, -654321, etc. 2. REAL for approximate, fractional

More information

Lecture 2 FORTRAN Basics. Lubna Ahmed

Lecture 2 FORTRAN Basics. Lubna Ahmed Lecture 2 FORTRAN Basics Lubna Ahmed 1 Fortran basics Data types Constants Variables Identifiers Arithmetic expression Intrinsic functions Input-output 2 Program layout PROGRAM program name IMPLICIT NONE

More information

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.

More information

2 Making Decisions. Store the value 3 in memory location y

2 Making Decisions. Store the value 3 in memory location y 2.1 Aims 2 Making Decisions By the end of this worksheet, you will be able to: Do arithmetic Start to use FORTRAN intrinsic functions Begin to understand program flow and logic Know how to test for zero

More information

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards Language Reference Manual Introduction The purpose of

More information

Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I. Lecture#12 Spring 2015 Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

1 Characters & Strings in Fortran

1 Characters & Strings in Fortran Handout Four March 2, 2006 1 Characters & Strings in Fortran 1.1 Declaration In handout two of your notes (section 2.3) you were briefly shown how to declare various character types. A table similar to

More information

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu) I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications

More information

7 Control Structures, Logical Statements

7 Control Structures, Logical Statements 7 Control Structures, Logical Statements 7.1 Logical Statements 1. Logical (true or false) statements comparing scalars or matrices can be evaluated in MATLAB. Two matrices of the same size may be compared,

More information

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

Review Functions Subroutines Flow Control Summary

Review Functions Subroutines Flow Control Summary OUTLINE 1 REVIEW 2 FUNCTIONS Why use functions How do they work 3 SUBROUTINES Why use subroutines? How do they work 4 FLOW CONTROL Logical Control Looping 5 SUMMARY OUTLINE 1 REVIEW 2 FUNCTIONS Why use

More information

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

More information

ME1107 Computing Y Yan.

ME1107 Computing Y Yan. ME1107 Computing 1 2008-2009 Y Yan http://www.staff.city.ac.uk/~ensyy About Fortran Fortran Formula Translation High level computer language Basic, Fortran, C, C++, Java, C#, (Matlab) What do we learn?

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

EE 301 Signals & Systems I MATLAB Tutorial with Questions

EE 301 Signals & Systems I MATLAB Tutorial with Questions EE 301 Signals & Systems I MATLAB Tutorial with Questions Under the content of the course EE-301, this semester, some MATLAB questions will be assigned in addition to the usual theoretical questions. This

More information

Flow Control: Branches and loops

Flow Control: Branches and loops Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the

More information

COMS 469: Interactive Media II

COMS 469: Interactive Media II COMS 469: Interactive Media II Agenda Review Data Types & Variables Decisions, Loops, and Functions Review gunkelweb.com/coms469 Review Basic Terminology Computer Languages Interpreted vs. Compiled Client

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Programming Basics and Practice GEDB029 Decision Making, Branching and Looping Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Decision Making and Branching C language possesses such decision-making capabilities

More information

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

Perl Basics. Structure, Style, and Documentation

Perl Basics. Structure, Style, and Documentation Perl Basics Structure, Style, and Documentation Copyright 2006 2009 Stewart Weiss Easy to read programs Your job as a programmer is to create programs that are: easy to read easy to understand, easy to

More information

ECE 202 LAB 3 ADVANCED MATLAB

ECE 202 LAB 3 ADVANCED MATLAB Version 1.2 1 of 13 BEFORE YOU BEGIN PREREQUISITE LABS ECE 201 Labs EXPECTED KNOWLEDGE ECE 202 LAB 3 ADVANCED MATLAB Understanding of the Laplace transform and transfer functions EQUIPMENT Intel PC with

More information

PHYS 210: Introduction to Computational Physics Octave/MATLAB Exercises 1

PHYS 210: Introduction to Computational Physics Octave/MATLAB Exercises 1 PHYS 210: Introduction to Computational Physics Octave/MATLAB Exercises 1 1. Problems from Gilat, Ch. 1.10 Open a terminal window, change to directory /octave, and using your text editor, create the file

More information

9. Elementary Algebraic and Transcendental Scalar Functions

9. Elementary Algebraic and Transcendental Scalar Functions Scalar Functions Summary. Introduction 2. Constants 2a. Numeric Constants 2b. Character Constants 2c. Symbol Constants 2d. Nested Constants 3. Scalar Functions 4. Arithmetic Scalar Functions 5. Operators

More information

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017 SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name] PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name] Content in [] is optional. Example:- PROGRAM FIRST_PROGRAM IMPLICIT NONE PRINT*,

More information

AMath 483/583 Lecture 7

AMath 483/583 Lecture 7 AMath 483/583 Lecture 7 This lecture: Python debugging demo Compiled langauges Introduction to Fortran 90 syntax Declaring variables, loops, booleans Reading: class notes: Python debugging class notes:

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0 VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 L J Howell UX Software 2009 Ver. 1.0 TABLE OF CONTENTS INTRODUCTION...ii What is this book about?... iii How to use this book... iii

More information

Control Structures: The IF statement!

Control Structures: The IF statement! Control Structures: The IF statement! 1E3! Topic 5! 5 IF 1 Objectives! n To learn when and how to use an IF statement.! n To be able to form Boolean (logical) expressions using relational operators! n

More information

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input CpSc Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input Overview For this lab, you will use: one or more of the conditional statements explained below scanf() or fscanf() to read

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

Program Structure and Format

Program Structure and Format Program Structure and Format PROGRAM program-name IMPLICIT NONE specification part execution part subprogram part END PROGRAM program-name Comments Comments should be used liberally to improve readability.

More information

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Fortran. (FORmula TRANslator) History

Fortran. (FORmula TRANslator) History Fortran (FORmula TRANslator) History FORTRAN vs. Fortran 1954 FORTRAN first successful high level language John Backus (IBM) 1958 FORTRAN II (Logical IF, subroutines, functions) 1961 FORTRAN IV 1966 FORTRAN

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Programming for Engineers Iteration

Programming for Engineers Iteration Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

More information

Is the statement sufficient? If both x and y are odd, is xy odd? 1) xy 2 < 0. Odds & Evens. Positives & Negatives. Answer: Yes, xy is odd

Is the statement sufficient? If both x and y are odd, is xy odd? 1) xy 2 < 0. Odds & Evens. Positives & Negatives. Answer: Yes, xy is odd Is the statement sufficient? If both x and y are odd, is xy odd? Is x < 0? 1) xy 2 < 0 Positives & Negatives Answer: Yes, xy is odd Odd numbers can be represented as 2m + 1 or 2n + 1, where m and n are

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1 A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

More information

AMath 483/583 Lecture 7. Notes: Notes: Changes in uwhpsc repository. AMath 483/583 Lecture 7. Notes:

AMath 483/583 Lecture 7. Notes: Notes: Changes in uwhpsc repository. AMath 483/583 Lecture 7. Notes: AMath 483/583 Lecture 7 This lecture: Python debugging demo Compiled langauges Introduction to Fortran 90 syntax Declaring variables, loops, booleans Reading: class notes: Python debugging class notes:

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 3 Creating, Organising & Processing Data Dr Richard Greenaway 3 Creating, Organising & Processing Data In this Workshop the matrix type is introduced

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 04 - Conditionals Stephen Scott (Adapted from Christopher M. Bourke) Fall 2009 1 / 1 cbourke@cse.unl.edu Control Structure Conditions

More information

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

Downloaded from Chapter 2. Functions

Downloaded from   Chapter 2. Functions Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create

More information

What is MATLAB and howtostart it up?

What is MATLAB and howtostart it up? MAT rix LABoratory What is MATLAB and howtostart it up? Object-oriented high-level interactive software package for scientific and engineering numerical computations Enables easy manipulation of matrix

More information

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu) I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications

More information

GraphQuil Language Reference Manual COMS W4115

GraphQuil Language Reference Manual COMS W4115 GraphQuil Language Reference Manual COMS W4115 Steven Weiner (Systems Architect), Jon Paul (Manager), John Heizelman (Language Guru), Gemma Ragozzine (Tester) Chapter 1 - Introduction Chapter 2 - Types

More information

Introduction to Programming with RAPTOR

Introduction to Programming with RAPTOR Introduction to Programming with RAPTOR By Dr. Wayne Brown What is RAPTOR? RAPTOR is a visual programming development environment based on flowcharts. A flowchart is a collection of connected graphic symbols,

More information

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements Topic 4 Variables Once a programmer has understood the use of variables, he has understood the essence of programming -Edsger Dijkstra What we will do today Explain and look at examples of primitive data

More information

Flow Control. So Far: Writing simple statements that get executed one after another.

Flow Control. So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow control allows the programmer

More information

Chapter 2, Part III Arithmetic Operators and Decision Making

Chapter 2, Part III Arithmetic Operators and Decision Making Chapter 2, Part III Arithmetic Operators and Decision Making C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson

More information

Physics 326G Winter Class 6

Physics 326G Winter Class 6 Physics 36G Winter 008 Class 6 Today we will learn about functions, and also about some basic programming that allows you to control the execution of commands in the programs you write. You have already

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

More information

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++. Concepts Review 1. An algorithm is a sequence of steps to solve a problem. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++. 3. A flowchart is the graphical

More information

It can be confusing when you type something like the expressions below and get an error message. a range variable definition a vector of sine values

It can be confusing when you type something like the expressions below and get an error message. a range variable definition a vector of sine values 7_april_ranges_.mcd Understanding Ranges, Sequences, and Vectors Introduction New Mathcad users are sometimes confused by the difference between range variables and vectors. This is particularly true considering

More information

Numerical Modelling in Fortran: day 2. Paul Tackley, 2017

Numerical Modelling in Fortran: day 2. Paul Tackley, 2017 Numerical Modelling in Fortran: day 2 Paul Tackley, 2017 Goals for today Review main points in online materials you read for homework http://www.cs.mtu.edu/%7eshene/courses/cs201/notes/intro.html More

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

INTRODUCTION TO FORTRAN PART II

INTRODUCTION TO FORTRAN PART II INTRODUCTION TO FORTRAN PART II Prasenjit Ghosh An example: The Fibonacci Sequence The Fibonacci sequence consists of an infinite set of integer nos. which satisfy the following recurrence relation x n

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

ME 461 C review Session Fall 2009 S. Keres

ME 461 C review Session Fall 2009 S. Keres ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help

More information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

Formulas and Functions

Formulas and Functions Conventions used in this document: Keyboard keys that must be pressed will be shown as Enter or Ctrl. Controls to be activated with the mouse will be shown as Start button > Settings > System > About.

More information

Compilation and Execution Simplifying Fractions. Loops If Statements. Variables Operations Using Functions Errors

Compilation and Execution Simplifying Fractions. Loops If Statements. Variables Operations Using Functions Errors First Program Compilation and Execution Simplifying Fractions Loops If Statements Variables Operations Using Functions Errors C++ programs consist of a series of instructions written in using the C++ syntax

More information

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132) BoredGames Language Reference Manual A Language for Board Games Brandon Kessler (bpk2107) and Kristen Wise (kew2132) 1 Table of Contents 1. Introduction... 4 2. Lexical Conventions... 4 2.A Comments...

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE

More information

(Refer Slide Time: 01:12)

(Refer Slide Time: 01:12) Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #22 PERL Part II We continue with our discussion on the Perl

More information

GeoCode Language Reference Manual

GeoCode Language Reference Manual GeoCode Language Reference Manual Contents 1 Introduction... 3 2 Lexical Elements... 3 2.1 Identifiers... 3 2.2 Keywords... 3 2.3 Literals... 3 2.4 Line Structure... 4 2.5 Indentation... 4 2.6 Whitespace...

More information

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++ Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Basic stuff -- assignments, arithmetic and functions

Basic stuff -- assignments, arithmetic and functions Basic stuff -- assignments, arithmetic and functions Most of the time, you will be using Maple as a kind of super-calculator. It is possible to write programs in Maple -- we will do this very occasionally,

More information

Statements and Operators

Statements and Operators Statements and Operators Old Content - visit altium.com/documentation Mod ifi ed by Rob Eva ns on Feb 15, 201 7 Parent page: EnableBasic Enable Basic Statements Do...Loop Conditional statement that repeats

More information

Repetition Structures Chapter 9

Repetition Structures Chapter 9 Sum of the terms Repetition Structures Chapter 9 1 Value of the Alternating Harmonic Series 0.9 0.8 0.7 0.6 0.5 10 0 10 1 10 2 10 3 Number of terms Objectives After studying this chapter you should be

More information

Programming with Python

Programming with Python Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2

More information

Introduction to the workbook and spreadsheet

Introduction to the workbook and spreadsheet Excel Tutorial To make the most of this tutorial I suggest you follow through it while sitting in front of a computer with Microsoft Excel running. This will allow you to try things out as you follow along.

More information

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB: Contents VARIABLES... 1 Storing Numerical Data... 2 Limits on Numerical Data... 6 Storing Character Strings... 8 Logical Variables... 9 MATLAB S BUILT-IN VARIABLES AND FUNCTIONS... 9 GETTING HELP IN MATLAB...

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1 Defining Program Syntax Chapter Two Modern Programming Languages, 2nd ed. 1 Syntax And Semantics Programming language syntax: how programs look, their form and structure Syntax is defined using a kind

More information

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

Special Section: Building Your Own Compiler

Special Section: Building Your Own Compiler cshtp6_19_datastructures_compiler.fm Page 1 Tuesday, February 14, 2017 10:31 AM 1 Chapter 19 Special Section: Building Your Own Compiler In Exercises8.31 8.33, we introduced Simpletron Machine Language

More information