Created
May 25, 2015 00:30
-
-
Save forrestwilkins/5fd157555ded875c9612 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# anything after a pound sign is just a comment, like notes, doesn't affect functionality at all | |
# this is a normal loop, since true is always true, the loop runs forever | |
while true # while evaluates whatever value it's given by the programmer | |
puts "This text gets printed to the screen over and over." | |
end # this is the end of the block. since it's a loop, | |
# the flow returns back to the top of the while block | |
# this is a recursive loop | |
@number = 0 # this is how you create variables, just little jars of data | |
def recurse # this is how you define a function, it's just a way of grouping code into more manageable chunks | |
puts @number # this prints the variable number to the screen | |
@number = @number + 1 # this is obvious | |
recurse # this is where the recursion happens | |
end | |
recurse # the recursive function is now called or executed | |
# you have something called control flow, basically just wherever the computer is currently at in your code | |
# so when the recursive function is called, it ends up calling itself again, before it's ever able to reach the end of itself | |
# thus you have what's called a stack overflow, when the call stack becomes so deep that the computer runs out of memory | |
# a great recipe for viruses in the 90s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment