Skip to content

Commit dd9f903

Browse files
Updated markdown
1 parent 2b3ed81 commit dd9f903

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

intro/03_loops/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Loops#
1+
# Loops
22

33
If I asked you to write a program that prints ```Hi, mom!``` three times, how would you write it? Probably something like this:
44

@@ -10,7 +10,7 @@ puts "Hi, mom!"
1010

1111
That's manageable, isn't it? Okay, but what if I asked you to do the same thing except 1000 times? A million times? This is where **loops** come to the rescue.
1212

13-
##While##
13+
## While
1414

1515
```ruby
1616
count = 0
@@ -31,7 +31,7 @@ while count < 1000 # Count will never equal 1000
3131
end
3232
```
3333

34-
##Until##
34+
## Until
3535

3636
Similar to ```unless``` and ```if```, ```until``` mirrors the behavior of ```while``` except it tests that a certain condition is false rather than true.
3737

@@ -46,7 +46,7 @@ end
4646
puts "Blast off!"
4747
```
4848

49-
##For##
49+
## For
5050

5151
**For-loops** are a common and popular alternative to **while-loops** when you must repeat a sequence of code a certain number of times. We can rewrite the above examples in the following way:
5252

@@ -80,7 +80,7 @@ The important thing to note about these for-loops is that they are storing the i
8080
end
8181
```
8282

83-
##Loop##
83+
## Loop
8484

8585
The last kind I'd like to mention is invoked using the ```loop``` keyword. Go figure.
8686

@@ -99,7 +99,7 @@ end
9999
puts "Game Over"
100100
```
101101

102-
##Break##
102+
## Break
103103

104104
Anything that you put in a ```loop``` block will happen infinitely unless you use the keyword ```break```. Using ```break``` inside of a loop will cause the program to leave that block of code and return to the next highest scope. Let's get a bit more complicated and show what that means.
105105

@@ -124,7 +124,7 @@ Outer block
124124

125125
From this, we can see that the break statement will only escape from whatever the immediate loop block of code is and return to the next highest scope.
126126

127-
##Next##
127+
## Next
128128

129129
The next closest relative to ```break``` is the keyword **next**. Using ```next``` in a loop will immediately skip to the subsequent iteration of the loop, ignoring the rest of the statements in the block.
130130

@@ -147,11 +147,11 @@ As you can see, while ```break``` leaves the entire enclosing loop immediately,
147147

148148
Finally, although Ruby also offers the ```redo``` and ```retry``` keywords when working with loops, you probably won't need to know them right now. If you're curious, please look them up and think of ways to use them.
149149

150-
#Knowledge Check#
150+
# Knowledge Check
151151

152152
1. Are variables declared in a for-loop available after a loop has ended?
153153

154-
#Assignment#
154+
# Assignment
155155
fibonacci.rb
156156

157157
The Fibonacci sequence is a popular programming exercise for new programmers. If you're not familiar with it, the first ten Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, and 55. You should be able to see a pattern in this sequence. Using conditionals and looping techniques we've covered so far, write some code that will print each of first ten Fibonacci numbers on its own line.

0 commit comments

Comments
 (0)