Control flow structure 2022 Best

This paper answers the following multiple choice questions: 1. Which of the following is NOT a control flow structure? ● procedure call ● selection statement ● conditional target ● Assignment statement. 2. Which programming languages do not have iteration statements and why?

Control flow structure

Multiple Choice: 1. Which of the following is NOT a control flow structure? ● procedure call ● selection statement ● conditional target ● Assignment statement. 2. Which programming languages do not have iteration statements and why? ● Object-Oriented Programming languages do not use iteration since functions operate over data structures. ● Functional programming languages do not have variables and iteration requires variables to operate. ● Functional programming languages since they do not use variables and counting loops require variables.  ● Imperative programming languages require recursion to do anything iteratively.

Control flow structure

3. One of the downsides of using expressions that produce results other than true or false is ● it is expensive to type-check ● it hurts readability since it may be confusion to know which route an execution will take. ● it hurts writability since we have to write such long expressions. ● it can cause side effects skewing the results of the rest of the code In mixed-mode expressions for Java, ● a narrowing conversion must be made explicitly via coercion ● a narrowing conversion must be made explicitly via casting.

Control flow structure

A widening conversion must be made explicitly via casting ● a narrowing conversion must be made implicitly via coercion. 4. Which operator is not technically necessary but provided to the programmer to allow them to control precedence and associativity of the expressions they write? ● braces {} ● subtraction – ● square braces [] ● parenthesis (). 5 Why do many programming languages (like Java) have break and continue but not goto? ● ● break and continue provide the same functionality without the overhead of goto ● ● break and continue can be used just like goto therefore goto is never necessary.

Control flow structure

Break and continue are special situation gotos which provide most of the functionality necessary without harming readability. ● ● break and continue are special situation gotos which are easier to use than goto. 6. If we wanted something like the python else statement for a counter controlled loop in Java, what would it look like? ● we check the for flag to see if loop terminated correctly ● We simply check break variable to see if used. ● We simply check either break or continue flags to see if either is set.

Control flow structure

Since there is no way for a loop in Java to tell you if it completed without breaks or continues, you’d need to set a Boolean flag to indicate that and check it after the loop was completed. Which of the following is NOT a multiple selection statement? ● if-elif-else ● guarded command ● case ● if-else Operator overloading is ● extremely common in PL since + works differently for ints and floats but it is uncommon for programming languages to allow the developer to overload operators ● very uncommon in programming languages ● extremely common in PL since + works differently for ints and floats and it is also common for programming languages to allow the developer to overload operators.

Control flow structure

Very uncommon in programming languages but some languages allow the programmer to overload all operators Suppose a new programming language that we are learning does not support short circuit evaluation for boolean expressions. What can a programmer to do to work around it? Consider the expression: while ((index < array.length) && (array[index] != target)) ● ● We could convert the loop into a series of if statements. ● ● We would use recursion. ● ● We could write two loops. ● ● We would simply nest them. https://youtu.be/UXeDS20wr60

Attached Files

 |

Powered by WordPress and MagTheme