Ruby Programming Language

Loops

By

First published on January 30, 2019


Loops allow us to repeat the same steps of code as many times as we desire without having to type that code multiple times.

A danger of loops that that a poorly coded loop can last forever. So we always wish to include a condition in the loop that will cause it to stop. The condition can be for the loop to run a specific number of times, or to keep running until a specified event occurs.

In the code below, the word whilecreate the condition.

[code lang=”ruby”]
while period < finalperiodlimit do lineargrowth = 1.0 ∗ period

exponentialgrowth = Math.exp(period)

end
[/code]

 


| COURSE |


Content is copyright the author. Layout is copyright Corsbook. See Corsbook.com for further notices.