Looping in Ruby vs. Looping in JavaScript

Week 6

Saturday, January 24, 2016

Looping in Ruby


Ruby has made looping much simpler to use because Ruby has much more looping methods build in. Such as .each, .each_with_index, while loops, until loops and even for loops. Some of the loops could be matched with .split methods which makes it great if you want to split at spaces as well. Because Ruby is a back end language. JS is used for both front end and back end they don't have as much build-in as language such as Ruby. they do have more of the back end therefor they have more tools to use because of that.

Because of there are more methods to choose from, choosing the right one to use could also be a bit confusing at times. Personally I prefer to use Ruby's looping methods because they give so much more options. However, maybe using JS more I could change my mind.



Loopping in JavaScript


While looping in JS is a bit more limited because of the while loop and for loop. It could be much simpler as well because you don’t really have much more options than that at current moment. I'm believe that JS is a hybrid language. JS is used for both front end and back end they don't have as much build-in as language such as Ruby.


Examples of "FOR" loop

        
        var x = 1;
        var i;
        for (i = 0; i < 10; i++) {
        x += 2;
        };
      

Example of "WHILE" loop

        
        var x = 0;
        while (x < 5) {
        console.log(‘Hi, There!’);
        x += 1
        };
      

There are many application that requires the use of one or the other. So we can have two choices to work with.