annotate 1-Ruby/blocks.rb @ 38:e8407d4e72dd

Add code on reflection - basically involves the object returned by "proto" message
author IBBoard <dev@ibboard.co.uk>
date Wed, 13 Sep 2017 20:11:52 +0100
parents 0374ae06729e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 #! /usr/bin/env ruby
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 x = 1
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 # Inline loops
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 x = x + 1 while x < 10
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 puts x
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 x = x - 1 until x == 1
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 puts x
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 # Conventional loops
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 while x < 10
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 x = x + 1
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 end
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 puts x
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 until x == 1
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 x = x - 1
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 end
0374ae06729e Start playing around with loop block definitions
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 puts x