The JavaScript For Loop resembles the for loop you may have seen in many other programming languages. It is used when you need to do a set of operations many times, with an increment of some kind after each run through the block of code.
for(i=0;i<=10;i++)
{
alert("Counter i = " + i);
}
For loop in ruby
for i in 0..10
puts "counter i is #{i}"
end
Now i had a javascript for loop with variable incremented to 2
for ( var i = 0; i <=10; i += 2 )
{
alert("Counter i = " + i);
}
Now in ruby i can go with step instead of default for
0.step(10,2) { |i| puts i }
No comments :
Post a Comment