Purchase Solution

Repetitive control structures, Techniques of passing arguments

Not what you're looking for?

Ask Custom Question

1. Discuss various counter controlled repetitive control structures.

2. The if...else is suitable for simple program but switch...case is a better construct, which is suitable for more complex problems? Do you agree with this or not? Discuss with suitable examples.

3. We can replace any code that uses a for loop with a while loop. Would not it be simpler to get rid of the for loop and use the while for everything? Do you think this would be a good idea? Why or why not?

4. Write a program using equality and assignment operator with their symbol. Which type of error is generated, using them incorrectly? Discuss the results.

5. Write the example that demonstrates different techniques of passing arguments: by value, by reference, and as pointers. Discuss the three methods.

Purchase this Solution

Solution Summary

Repetitive control structures for techniques of passing arguments are determined.

Solution Preview

Solution 1:
"Loops" are considered to be the repetitive control structures. They can either be event-controlled or counter controlled. The following are some of the repetitive counter controlled structures:
1) "for" loop
2) "while" loop
3) "do-while" loop
"for" loop
In this kind of loop, the loop body executes some fixed number of times according to the condition specified. A for loop header consists of an initialization statement, a condition and an increment statement; out of which the initialization and increment statements are optional.
This loop is basically used to perform repetitive action where count of repetition is known beforehand.

for( int i=10; i <= 50 ; i =i + 5)
{
Statement 1;
.
.
.
Statement n;
}

This loop starts from i = 10 and execute till i becomes 50 with the increment of 5 after each iteration.

"while" loop
In this case, the loop body executes until the condition is true in while structure. In the example given below, the variable i is declared out of the while structure and the statements in while loop are executed as long as the variable is less than 50. In the while loop, we have to provide some statement to break the condition so that it will not go into infinite loop. For the same reason the variable i is incremented at the end of loop body in the example.

condition

while(i<50) {
Statement 1;
.
.
.
Statement n;
++i; increment

}

"do-while" loop
Do-while loop is similar to while loop except that the statements are executed at least once before the condition is checked. Like in the below given example, the statement is executed for the first time without checking the condition of the do-while statement. Even if the variable i is greater than ...

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.