programming sequence, selection and iteration Flashcards

(15 cards)

1
Q

What is the definition of Sequence in C# programming?

A

Instructions are performed in the order they are listed.

The sequence can contain any number of lines, and none can be left out.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the output of the following code:
int num1 = 10;
int num2 = 5;
int answer1 = num1 + num2;

A

15

The variable answer1 stores the sum of num1 and num2.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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”);
}

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fill in the blank: A program makes a decision during the _______ process.

A

Selection

Selection involves testing conditions and executing code based on the results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of an if statement?

A

To execute code if a specified condition is true.

It allows branching in the code based on logical conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does a While Loop do in C#?

A

Repeats a section of code while a condition is true.

It is a type of iteration structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Complete the code:
Console. (“What age are you?”);
age = .ToInt16( Console.ReadLine() );

A

WriteLine, Convert

These are necessary to prompt user input and convert it to an integer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the output of the code if num1 = 4 and num2 = 6?

A

Num1 is smaller

The condition num1 < num2 evaluates to true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the structure of an if statement with an else?

A

IF (this thing is true)
Do this
Otherwise
Do this code

This structure allows for alternative code execution based on a condition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the For Loop do?

A

Repeats a section of code a set number of times.

It is a type of count-controlled loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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.

A

condition

This highlights the flexibility of iteration in programming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

True or False: The sequence of instructions in a program can leave out lines.

A

False

All lines must be included in the sequence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the output when age >= 65 if people 65 or older get free fare

A

Free Fare

This output is part of a conditional statement assessing age.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens in an if with an else if and an else structure?

A

It allows multiple conditions to be tested in sequence.

Only the first true condition will execute its corresponding code block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the result of the operation: int answer5 = (num1 - num2) * num2; if num1 = 10 and num2 = 5?

A

25

The calculation follows standard order of operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly