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.© BrainMass Inc. brainmass.com March 4, 2021, 10:26 pm ad1c9bdddf
"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
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)
This loop starts from i = 10 and execute till i becomes 50 with the increment of 5 after each iteration.
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.
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 ...
Repetitive control structures for techniques of passing arguments are determined.