Hardware Reference
In-Depth Information
The for statement
Another useful construct is the for construct; it will allow us to execute a set of statements
over and over for a specific number of times. The following screenshot shows an example
using this construct:
The code in the preceding screenshot looks very similar to the code you've used before, but
we've added two examples of the for construct. Some details of the loop() function are
as follows:
for (int i = 0; i < 5; i++) : This loop consists of three elements. The
int i = 0; is the initializer statement. It is only done once when you first ex-
ecute the loop. In this case, the initializer statement creates a storage location
named i and puts the value of 0 in it. The second part of the loop statement is the
check statement. In this case, the check statement is i < 5 . If the statement is
true, the loop executes. If it is false, the loop stops and the program goes to the
next statement after the for loop. The final part of the for loop is a statement
that is executed at the end of each loop. In this case, the statement i++ simply
Search WWH ::




Custom Search