programming sequence, selection and iteration Flashcards
(15 cards)
What is the definition of Sequence in C# programming?
Instructions are performed in the order they are listed.
The sequence can contain any number of lines, and none can be left out.
What is the output of the following code:
int num1 = 10;
int num2 = 5;
int answer1 = num1 + num2;
15
The variable answer1 stores the sum of num1 and num2.
What is the output of the following code:
if (num1 > num2)
{
Console.WriteLine(“A”);
}
else if (num1 < num2)
{
Console.WriteLine(“B”);
}
else
{
Console.WriteLine(“C”);
}
Depends on values of num1 and num2:
* A for num1 > num2
* B for num1 < num2
* C for num1 == num2
The program tests conditions to determine which output to display.
Fill in the blank: A program makes a decision during the _______ process.
Selection
Selection involves testing conditions and executing code based on the results.
What is the purpose of an if statement?
To execute code if a specified condition is true.
It allows branching in the code based on logical conditions.
What does a While Loop do in C#?
Repeats a section of code while a condition is true.
It is a type of iteration structure.
Complete the code:
Console. (“What age are you?”);
age = .ToInt16( Console.ReadLine() );
WriteLine, Convert
These are necessary to prompt user input and convert it to an integer.
What is the output of the code if num1 = 4 and num2 = 6?
Num1 is smaller
The condition num1 < num2 evaluates to true.
What is the structure of an if statement with an else?
IF (this thing is true)
Do this
Otherwise
Do this code
This structure allows for alternative code execution based on a condition.
What does the For Loop do?
Repeats a section of code a set number of times.
It is a type of count-controlled loop.
Fill in the blank: An iteration allows a program to repeat a section of code either for a set number of times or while a _______ is true.
condition
This highlights the flexibility of iteration in programming.
True or False: The sequence of instructions in a program can leave out lines.
False
All lines must be included in the sequence.
What is the output when age >= 65 if people 65 or older get free fare
Free Fare
This output is part of a conditional statement assessing age.
What happens in an if with an else if and an else structure?
It allows multiple conditions to be tested in sequence.
Only the first true condition will execute its corresponding code block.
What is the result of the operation: int answer5 = (num1 - num2) * num2; if num1 = 10 and num2 = 5?
25
The calculation follows standard order of operations.