Created by Ruth Hyndman
almost 9 years ago
|
||
Question | Answer |
Name 3 control structures | Sequential Selection Repetition/Iteration |
Describe the Sequential control structure. | A list of instructions are carried out one after another in a predetermined order. No actions can be skipped. |
Describe the Selection control structure. | The program control branches to specific flows based on whether or not a condition is true. |
Name 2 key selection constructs | There are 2 key selection constructs, if statements and switch statements. |
What does an IF statement do? | An if statement carries out a set of statements if a condition is true and ignores them if a condition is false. They use the key words if, else and else if. |
What is an IF ELSE statement? | This is an extenstion of the IF statement. It will execute a block of code when a condition is true and an alternative block of code if the condition is false. |
What is an ELSE IF statement? | This is very similar to an else statement but has an extra condition. It will run block of code if a condition is true, a different one if the first was false and the second condition is true and so on. |
What is a Switch statement? | This allows a variable to be tested against a list of values. The value changes the control flow of program execution via a multiway branch. Switch statements use the keywords switch, case, default and break. Break must be used in-between cases. |
What are the benefits of Switch statements? | They are effective when comparing one variable against many values. Often they are easier to read than a collection of ifs and else ifs. |
Describe the Repetition control structure. | The program control repeats a set of statements until a condition is met. AKA iteration |
What does a For loop do? | A For loop executes its statements a specified number of times. They are used whenever the number of repetitions is known or can be calculated. They are useful for processing data or arrays. |
What does a While loop do? | A While loop executes its statements as long as its condition is true. They are known as pre-test loops as the condition is checked before any statements are executed. If the condition is always true, an infinite loop will occur. |
What are the benefits of While loops? | The fact that it is a pre-test loop means that the loop can be exited without any of its statements being executed. This makes it useful for validation. |
What is a Do While loop? | A Do While loop executes its statements as long as its condition is true. It differs from the While loop because it is a post-test loop meaning the condition check takes place after all the statements have been executed. If the condition is always true, an infinite loop will occur. |
What are the benefits of Do While loops? | The fact that it is a post-test loop means that all of its statements will be executed at least once. |
What is the benefit of Repetition statements. | Statements do not have to be written over and over as they can be repeated. This cuts down on code and simplifies the program. |
Want to create your own Flashcards for free with GoConqr? Learn more.