ruby control structures
play

Ruby Control Structures Venkat Subramaniam svenkat@cs.uh.edu 1 - PDF document

Ruby Control Structures Venkat Subramaniam svenkat@cs.uh.edu 1 Statements Statements dont need ; You write one statement per line (like you normally do anyways) If you want to put multiple statements on a line, you may use


  1. Ruby Control Structures Venkat Subramaniam – svenkat@cs.uh.edu 1 Statements • Statements don’t need ; • You write one statement per line (like you normally do anyways) • If you want to put multiple statements on a line, you may use the optional ; Venkat Subramaniam – svenkat@cs.uh.edu 2

  2. Conditions • if statement does not need { } • Short forms Venkat Subramaniam – svenkat@cs.uh.edu 3 Looping • while loop is similar to what you’re used to More concise form Venkat Subramaniam – svenkat@cs.uh.edu 4

  3. For loops There are some other cool ways as well, but we’ll have to wait for that until we learn about blocks Venkat Subramaniam – svenkat@cs.uh.edu 5 Notice the Range • We used 1..10 and 1..val • Range is a first class citizen in Ruby • You can create range objects • It comes in handy in various situations… we’ll see these when discussing collections Venkat Subramaniam – svenkat@cs.uh.edu 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend