IDL Tutorials: Day 4 Goal: Learn some programming techniques: Relational operators, conditional statements, boolean operators, loops Angela Des Jardins.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Intro to Java while loops pseudocode. 1 A “Loop” A simple but powerful mechanism for “making lots of things happen!” Performs a statement (or block) over.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Lab 8 Shell Script Reference:
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
IDL Tutorials: Day 4 Goal: Learn some programming techniques: Relational operators, conditional statements, boolean operators, loops Maria Kazachenko
I Power Higher Computing Software Development High Level Language Constructs.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Shell Script2 Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 4 – Logical Operators & Branching.
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.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Lab 8 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Shell script – part 2 CS 302. Special shell variable $0.. $9  Positional parameters or command line arguments  For example, a script myscript take 2.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Perl Chapter 3 Conditional statements. Control Expressions Control expressions – interpreted as T/F (evaluated as strings or numbers) – simple, relational,
Computational Astronomy 제 5 장 프로그래밍 기초 전산천문학 봄.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
CGS 3066: Web Programming and Design Spring 2017
Chapter 9 Repetition.
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
Conditional Statements and Control Structure
JavaScript: Control Statements.
Agenda Control Flow Statements Purpose test statement
Introduction to MATLAB
Control Structures: if Conditional
Chapter 9 Control Structures.
Control Structures: for & while Loops
Logical Operations In Matlab.
Visual Basic – Decision Statements
Selection Statements.
Intro to Programming CURIE 2011.
Computer Science Core Concepts
ICT Programming Lesson 3:
Presented by, Mr. Satish Pise
The structure of programming
ASP control structure BRANCHING STATEMENTS
CGS 3066: Web Programming and Design Spring 2016
How to allow the program to know when to stop a loop.
Lecture 9: JavaScript Syntax
REPETITION Why Repetition?
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Control Structures.
Presentation transcript:

IDL Tutorials: Day 4 Goal: Learn some programming techniques: Relational operators, conditional statements, boolean operators, loops Angela Des Jardins

Relational Operators  Relation operators test the relationships between two arguments  Relation operators return 1 if they are true, 0 if false  Can be used on strings; also there are special functions for comparing strings  Common R.O’s - eq ; equal to - ne ; not equal to - lt ; less than - gt ; greater than - ge ; greater than or equal to - le ; less than or equal to  Syntax: Arg1 R.O. Arg2 IDL> print, 1 gt –1> print, array_1 le array_2

If Statements  One type of statement that allows program to make decisions  If statements use R.O.’s as a condition. If the R.O returns 1 (true) then the statement executes  An optional else statement can be included, giving an option to do something if the R.O. returns 0 (false)  Syntax: IF condition THEN something  Examples:  If x ge y then print, x  If x gt y then biggest= x else biggest=y  IF n_params() lt 1 then print, ‘you need a parameter’

Loops  Loops allow for actions to occur repeatedly  Usual syntax is conditional_statement BEGIN do something do_something_else endstatement;  Many types of loops -for loops -while loops -repeat loops * If you’re not careful your loop might not end. If you make an infinite loop CTRL+C can be used to break out of it.

Blocks  A block is a group of statements that are treated as a single statement  Blocks and Common Blocks are different things  Blocks usually begin with the word BEGIN and end with a particular end-statement depending on what statement the block is contained in. IF (R.O) then BEGIN …. Statements … ENDIFor FOR index = 0, n_elements(array) DO BEGIN … statements … ENDFOR

For Loop Syntax and Examples  For statements repeat a statement until a counter reaches an assigned value  The the counter is automatically advanced by one after each step Syntax: > FOR counter=value, number DO statement or > FOR counter=value, number DO BEGIN … statements > ENDFOR Examples: > FOR counter=0,10 DO print, cos(((2*!pi)/10)*counter) > FOR index=0, n_elements(array)-1 DO BEGIN > array[*,index]=cos(array_3[index,*]) > ENDFOR

While Loop Syntax and Examples  While loops repeat until some conditional statement is met Syntax > WHILE condition DO statement or > WHILE condition DO BEGIN …statements… > ENDWHILE Examples: > WHILE x ge y DO x=x-5 > WHILE x lt y DO BEGIN > x=x+5 > print, x > ENDWHILE

Repeat Loop Syntax and Examples  Repeat loops repeat until some conditional statement is met  Difference between repeat and while loops is the location of the conditional statement Syntax: > REPEAT statement UNTIL condition or or > REPEAT BEGIN > … statements… > ENDREP UNTIL condition Examples: > REPEAT x=x-5 UNTIL x lt y > REPEAT BEGIN >x=x+5 > print, x > ENDREP UNTIL x gt y

Boolean Operators  Boolean operators can be used to make complex groupings of conditional statements e.g. if (x lt y) and (x lt z) then print, ‘x is small’  There are four basic boolean operators - and; returns true when both of it’s operands are true > print, (1 lt 2) and (1 lt 3) ; IDL prints 1 > print, (1 lt 2) and (1 gt3) ; IDL prints 0 - or; Returns true when either of it’s operands are true > print, (1 lt 2) or (1 gt 3) ; IDL prints 1 > print, (1 gt 2) or (1 gt 3); IDL prints 0 - not; Boolean inverse operator - xor; boolean exclusive or function. Only good for certain data types. * Just about any logic making steps you need can be made with if’s or’s and and’s.

“Homework”  Find some example programs (just use xdoc if you don’t know any) and browse through the code looking for blocks. When you see loops or if, then statements, find where they begin and end. Can you see how the program works?  Come up with a simple problem that you can solve using the logic and/or loop statements you learned today. Write a program (procedure or function) that solves/displays the problem. Be prepared to share your program and run it in class tomorrow (it needs to “live” somewhere I can access it).