Question

In: Computer Science

Respond to the following in a minimum of 175 words: The flow of a program is...

Respond to the following in a minimum of 175 words:

The flow of a program is controlled by different structures. The three basic control structures in computer programs are sequence structures, decision structures (also called selection structures), and repetition structures (also called iteration structures).

Discuss the differences between decision structures and repetition structures used in algorithms. Provide examples of when you might use each.

Solutions

Expert Solution

The three basic control structures for any program are :

  • Sequence Structure: Sequence structure is like following a recipe where one step is followed after another step by step. In this, the instructions execute in the same order as they are written in the script.
  • Selection Structure: In this structure, the code executes based on the decision made by the currently executing line of code. Depending on whether the condition is true or false, the code skips to the next block for further execution. Example: if-else block, switch condition, etc.
  • Repetition / Iteration Structure: In case of iteration the same statement of code is executed multiple times as specified until the condition has been met. It includes for loops, while loops etc.

The difference between decision structure and Repetition structure used in algorithms:

1. Decision Structure: These statements make evaluations based on the comparator operators used in the statements lile ' = ' , '>' , '<' ,'>=' , '<=' , '==' etc. It can also contain boolean operators like OR operator, AND operator and the overall output of the expression determines the output. The precedence rule of operators must always be taken into consideration for the evaluation of these expressions.

  • If-Else Algorithm

if (Condition set according to the user )

{

//block of code for execution

}

else if (Another condition set according to the user)

{

//block of code for execution

}

else

{

// the block of code that executes when the above conditions are not satisfied

}

  • Switch Algorithm

Switch (the value that will act as switching parameter) :

{

case 1 : // block of code for execution

break;

case 2 : // block of code for execution

break;

break://Default block of code that executes if none of the conditions match

}

2. Repetition Structure

  • For Loop Algorithm

for(initialization, condition for looping, increment)

{

//Block of code for execution.

}

Example: for(int i=0;i<5;i++)

{

System.out.println("Hello World ");

}

  • While Loop Algorithm

initialization

while(condition that needs to be satisfied for execution)

{

//block of code for execution

( increment or decrement operator if required)

}

  • Do-While Loop Algorithm (Advantage : Executes minimum one time)

do

{

// block of code for execution

} while( condition )


Related Solutions

Respond to the following in a minimum of 175 words: An audit program relates to the...
Respond to the following in a minimum of 175 words: An audit program relates to the inventory/warehousing and payroll cycles and accounts.   Discuss tests of controls and substantive tests of transactions for the payroll and personnel cycle. How does this apply to your chosen organization?
Respond to the following in a minimum of 175 words: An audit program relates to the...
Respond to the following in a minimum of 175 words: An audit program relates to the cash, sales and receivables cycles and accounts. Discuss audit procedures for the audit of accounts receivable.
Respond to the following in a minimum of 175 words: It is important to program your...
Respond to the following in a minimum of 175 words: It is important to program your code efficiently. Efficient code manages errors and exceptions and cleans up memory after it ends. The try-except statements are helpful in handling errors that are detected during execution. What are the two categories of errors when debugging code? How can the try-except statements handle errors in Python? Provide a code example that supports your comments.
Respond to the following in a minimum of 175 words PLEASE TYPE RESPONSE: Cash flow analysis...
Respond to the following in a minimum of 175 words PLEASE TYPE RESPONSE: Cash flow analysis is 1 of the most important processes that firms can conduct to keep the company running smoothly. For small businesses that may not be equipped to easily obtain short-term financing, cash flow analysis becomes an essential component for financial success.   Discuss the primary problem with cash flow analysis. Discuss 2 additional issues that makes cash flow analysis difficult.
Respond to the following in a minimum of 175 words: What is the purpose of an...
Respond to the following in a minimum of 175 words: What is the purpose of an income statement, and who is the audience for this document? What components do income statements typically contain? Why?
Respond to the following in a minimum of 175 words: What is the purpose of a...
Respond to the following in a minimum of 175 words: What is the purpose of a Comprehensive Annual Financial Report, or CAFR? What standards must a CAFR comply with? What statements comprise a CAFR?
Respond to the following in a minimum of 175 words: In the early weeks of this...
Respond to the following in a minimum of 175 words: In the early weeks of this course, you learned some valuable skills for communicating within and improving the performance of teams you might be working with. This week, we will explore two crucial aspects of being on a team. We will learn about leadership and what it takes to be a good leader. We also examine conflict management and learn some ways to navigate through the inevitability of encountering conflict....
respond to the following in a minimum of 175 words: This week focuses on criteria for...
respond to the following in a minimum of 175 words: This week focuses on criteria for calculating capital changes and consolidated financial statements. Discuss the criteria for calculating capital changes. How do you calculate change in working capital from balance sheet?
respond to the following in a minimum of 175 words: This week focuses on criteria for...
respond to the following in a minimum of 175 words: This week focuses on criteria for calculating capital changes and consolidated financial statements. Discuss the criteria for calculating capital changes. How do you calculate change in working capital from balance sheet?
Respond to the following in a minimum of 175 words: What are the goals of conducting...
Respond to the following in a minimum of 175 words: What are the goals of conducting an audit of financial statements and internal controls? Who typically conducts such audits, how often, and for whom?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT