Saturday, 17 August 2013

Braces in FOR type loop code changed result unexpectedly

Braces in FOR type loop code changed result unexpectedly

I'm learning JS. In book is some exercise to make same code by using for
keyword instead of while as it was original example of loop of printing #
sign into lines to look like triangle:
#
##
###
####
#####
######
This was original example of doing it by using while keyword:
var line = "";
var counter = 0;
while (counter < 10) {
line = line + "#";
print(line);
counter = counter + 1;
}
I was did same using for without braces, because in this other example it
is not in need:

No comments:

Post a Comment