Grabbag – A Bunch of Other Stuff

Slides:



Advertisements
Similar presentations
Using Algebra Tiles to Understand How to Solve Equations.
Advertisements

SFTW241 Group A4 Presentation of Grouping Process.
And other languages….  Selection Statements  Iterative Statements  Unconditional Branching  Not covered Guarded Commands.
More Perl Control Flow Software Tools. Slide 2 Control Flow l We have already seen several Perl control flow statements: n if n while n for n last l Other.
This Presentation will take you on a tour with the greatest rock and roll band of all time. Presented By: Nick Mangone Project 11 May 24, 2011 Next.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Changing Control.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 3 Control Structures.
12-Jun-15 JavaScript Language Fundamentals I. 2 About JavaScript JavaScript is not Java, or even related to Java The original name for JavaScript was.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
1 MATERI PENDUKUNG JUMP Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Learning Ruby - 12 Grabbag II - The Grabbag Strikes Back!
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
5.05 Apply Looping Structures
Led Zeppelin - From The Beggining.
1 Python Control of Flow and Defining Classes LING 5200 Computational Corpus Linguistics Martha Palmer.
Using Control Structures. Goals Understand the three basic forms of control structures Understand how to create and manage conditionals Understand how.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004.
Control Structures. if-elsif-else semantically the same as C/C++ syntactically, slightly different. if ($a > 0){ print “\$a is positive\n”; } elsif ($a.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Books. Perl Perl (Practical Extraction and Report Language) by Larry Wall Perl 1.0 was released to usenet's alt.comp.sources in 1987 Perl 5 was released.
CSD 340 (Blum)1 Switch and While. CSD 340 (Blum)2 From if to switch.
Chapter 05 (Part III) Control Statements: Part II.
Week 3 - Wednesday.  What did we talk about last time?  Other C features  sizeof, const  ASCII table  printf() format strings  Bitwise operations.
CSE 425: Control Flow I Categories of Control Flow Constructs Sequencing –order of expressions and statements Selection –if, else, switch Iteration –loops.
Iteration Statements CGS 3460, Lecture 17 Feb 17, 2006 Hen-I Yang.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
CPTG286K Programming - Perl Chapter 4: Control Structures.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Rylie Eames CIS 1020 Final Project
Famous Person of the 70’s: Robert Plant (Turn up your sound!) Presentation by: Gannon Trueman Period 0 6/8/06.
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
Lecture 01b: C++ review Topics: if's and switch's while and for loops.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.
Perl Chapter 3 Conditional statements. Control Expressions Control expressions – interpreted as T/F (evaluated as strings or numbers) – simple, relational,
Week 3 - Friday.  What did we talk about last time?  Preprocessor directives  Other C features  sizeof, const  ASCII table  printf() format strings.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Imperative Programming Statements and invariants.
Chapter 6: Loops.
生查子 ~ 歐陽修 去年元夜時,花市燈如晝, 月上柳梢頭,人約黃昏後; 今年元夜時,月與燈依舊, 不見去年人,淚濕春衫袖。
Control Flow Constructs: Conditional Logic
The 1970s Rock and Roll Band.
Think What will be the output?
CS1010 Programming Methodology
Sequential Design.
Chapter 5 Structures.
Looping and Repetition
FLOW OF CONTROL.
تعارف. تعارف قواعد العمل ا الموبيل المشروبات الاحاديث الجانبية الاسئلة نفكر.
MSIS 655 Advanced Business Applications Programming
CIT 383: Administrative Scripting
Chapter 4 - Program Control
Control Structures: for & while Loops
Structured Programming Taken from notes by Dr. Neil Moore
Coding Concepts (Basics)
Matlab tutorial course
Iteration Implemented through loop constructs (e.g., in C++)
Testing and Repetition
Looping III (do … while statement)
Variables, Assignments Testing + Iteration
Introduction to Computer Science
Introduction to Computer Science
The structure of programming
Chapter 3: Selection Structures: Making Decisions
Thinking procedurally
Haidong Xue Summer 2011, at GSU
EE 194/BIO 196: Modeling biological systems
Presentation transcript:

Grabbag – A Bunch of Other Stuff Learning Ruby - 11 Grabbag – A Bunch of Other Stuff

Ruby Naming Conventions Diagram taken from page 17 of The PickAxe.

Operator Expressions Diagram taken from page 339 of The Pickaxe.

Fun with `backticks` `date` `ls` `ls`.split `ls`.split[-1] `uptime` puts $? `ls rubbbbish` `ls /etc/passwd`

Swapping Values temp = a a = b b = temp a, b = b, a

if and unless if song.artist == "Crowded House" then song.play elsif song.artist == "Snow Patrol" then song.hold else song.delete! end # of if. unless song.artist == "Led Zeppelin" song.turn_up!( 20 ) song.turn_down!( 20 ) end # of unless. song.artist == "Led Zeppelin" ? song.turn_down!( 20 ) : song.turn_up!( 20 )

if Assignments lead_singer = if song.artist == "Crowded House" "Neil Finn" elsif song.artist == "Led Zeppelin" "Robert Plant" elsif song.artist == "The Beatles" "John, Paul, John or Ringo" else "unknown" end # of if.

Statement Qualifiers File.foreach( "/etc/fstab" ) do |line| # Borrowed from page 98 of The PickAxe. File.foreach( "/etc/fstab" ) do |line| # Skip comments. next if line =~ /^#/ # Parse line if it's not empty. parse( line ) unless line =~ /^$/ end # of do.

The Case for Case album_title = case year when 1969 then "Led Zeppelin and Led Zeppelin II" when 1970 then "Led Zeppelin III" when 1971 then "(unnamed)" when 1973 then "Houses of the Holy" when 1975 then "Physical Graffiti" when 1976 then "Presence and The Song Remains The Same" when 1979 then "In Through The Out Door" else "unknown" end # of case.

What's All This then? With if and case, the then keyword is (sometimes) optional When the expression is on the same line as the condition, the then is required When it isn't, well ... it isn't The word then can be replaced with : when used on the same line: album_title = case year when 1969 : "Led Zeppelin and Led Zeppelin II" when 1970 : "Led Zeppelin III" ...

Loops Ruby supports while, until and for Ruby also supports iterators (as we've already seen) which are just like loops Loops also support break, next, redo and retry There's also a loop loop: loop do # This code will execute forever ... end # of loop.

There's Much More to Ruby Chapter 22 of The PickAxe is the concise reference to the Ruby Language ... take the time to browse these 45 pages In fact, pick up a copy of The PickAxe and keep it by your side while programming Ruby And remember ... Ruby is known as a fun programming language ... it's quite OK to have fun while programming (imagine that!)