Adding More Expressions into for
Adding More Expressions into for
The C language allows you to put more expressions into the three expression fields in the for statement. Expressions in a single expression field are separated by commas.
Adding More Expressions into for
The C language allows you to put more expressions into the three expression fields in the for statement. Expressions in a single expression field are separated by commas.
Looping Under the for Statement
The general form of the for statement is
for (expression1; expression2; expression3) {
statement1;
statement2;
.
.
.
}
Using Nested Loops
You can put a loop inside another one to make nested loops. The computer will run the inner loop first before it resumes the looping for the outer loop.
Listing 7.7 is an example of how nested loops work.
The do-while Loop
You may note that in the for and while statements, the expressions are set at the top of the loop. However, in this section, you're going to see another statement used for looping,
The while Loop
The while statement is also used for looping. Unlike the situation with the for statement, there is only one expression field in the while statement.
The general form of the while statement is
while (expression) {
Exercises : Answer the following Question
To help you solidify your understanding of this hour's lesson, you are encouraged to try to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.
Working with the Cast Operator
Playing with the Cast Operator
In C, you can convert one data type to a different one by prefixing the cast operator to the operand.
The general form of the cast operator is
(data-type)x
Question and Answer
Question and Answer
Q What is the difference between the pre-increment operator and the post-increment operator?