How did we produce such a table?
Well, our code uses two for loops to produce that table. Before we say more about the loops, let's start reviewing from the beginning of the code.
With this line, all we are saying is that we want to create a HTML table.
Note how the value for each of the table properties such as border, width, cellspacing, and cellpadding is enclosed by single quotation marks. Recall that a table tag creates a table in HTML.
We could have used a document. It is actually more efficient to use a variable for output instead of repeatedly calling the document. So, in this example, each time we want to print something to the web page, we simply assign the output to the variable sout.
Line 4 has our first for loop ; we could refer to this loop as an outer loop.
It is an outer loop, as the name implies, because it inside contains a loop. The loop inside an outer loop is called an inner loop, see line 6.
Let's now describe what is happening inside the loops, lines 4 through 8. The second time the inner loop executes, the second cell is created with the value 2; then the third cell is created with the value of 3, and so on. When inner loop stops executing when j reaches 10, the first row is filled with 10 cells.
Similarly, remaining rows and cells are created. We can also use a while loop to create nested loops.
See the following code that produces the same output as you saw with the nested for loop:For instance, look at the next example where, with three loops, we can write over 16 million colors!
In order not to make the page slow, we have drastically reduced the number by putting the step to 30 and thereby limited the number of colors to One-Page Version tranceformingnlp.com Multipage Version /multipage Developer Version /dev PDF Version /tranceformingnlp.com Translations 日本語 • 简体中文.
Using arrays with for loops. The main reason to use arrays is convenience. When you have a lot of information in an array, you can write code to work with the data quickly. Documentation for Particle, a platform for connected devices.
ruby: Capitalized variables contain constants and class/module names. By convention, constants are all caps and class/module names are camel case.
Logical operators are typically used with Boolean (logical) values. When they are, they return a Boolean value. However, the && and || operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value.