Skip to Main Content
Learn to Program, 2nd Edition
book

Learn to Program, 2nd Edition

by Chris Pine
March 2009
Intermediate to advanced content levelIntermediate to advanced
194 pages
4h
English
Pragmatic Bookshelf
Content preview from Learn to Program, 2nd Edition

Chapter 4Variables and Assignment

So far, whenever we have putsed a string or a number, the thing we putsed is gone. What I mean is, if we wanted to print something out twice, we would have to type it in twice:

puts ​'...you can say that again...'
puts ​'...you can say that again...'
...you can say that again...
...you can say that again...

It would be nice if we could just type it in once and then hang on to it…store it somewhere. Well, we can, of course. It would have been insensitive to bring it up otherwise.

To store the string in your computer’s memory for use later in your program, you need to give the string a name. Programmers often refer to this process as assignment, and they call the names variables. A variable name can usually ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn to Program, 3rd Edition

Learn to Program, 3rd Edition

Chris Pine
The Book of Ruby

The Book of Ruby

Huw Collingbourne

Publisher Resources

ISBN: 9781680500172Errata