1/20
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a Loop Statement?
A Loop Statement allows us to execute a statement or group of statements multiple times.
What is the purpose of a Looping Statement?
It is a program instruction that repeats some statements or a sequence of statements a specified number of times.
Name the two types of loops.
Finite loops (Index Loops) 2. Infinite loops (Unended Loops)
What are the examples of controlled loops?
Count Controlled Loop (For Loop) 2. Event Controlled Loop (While Loop, Do While Loop)
What is incrementation?
An operation that increases the value of a variable by one, e.g., num++.
What does the Decrement operation do?
Decrement reduces the value of a variable by one, e.g., num--.
What is Accumulation in loops?
It refers to adding a value to a variable, e.g., num = num + 2.
What is the syntax for a While Loop in C++?
initialization; while(condition){ statements; inc/dec/acc; }.
Write a simple program to display numbers from 10 to 1 using a While Loop.
What will the following code output? int x = 1, y = 0; while(x!=10){ x = x+2; y = y + x; cout << x << " " << y << endl; }
This will output a sequence of numbers based on the conditions of the loop.
What is the syntax of a For Loop?
for(initialization; condition; inc/dec/acc){ statements; }.
How do you find the average using a For Loop?
Prompt for the number of values, accumulate their sum, and divide by count.
What differentiates a do…while loop from other types of loops?
The do…while loop checks its condition at the bottom of the loop, ensuring that it executes at least once.
What is the syntax for a do…while loop?
initialization; do { statements; inc/dec/acc; }while(condition);.
In a nested loop, where is one loop placed?
One loop is placed inside the body of another loop.
What is a common programming error with the For Loop?
Using commas instead of semicolons to separate expressions.
What happens if you place a semicolon at the end of a For Loop?
The loop may run incorrectly or not execute its intended body.
What does the term 'Common Programming Error' refer to?
It highlights frequent mistakes programmers make while writing code.
How can you code a For Loop from 0 to 24 increasing by 3?
for(counter = 0; counter<=24; counter+=3){ cout << counter << " . Hello TIP..." << endl; }.
What is the output of the provided code segment using a For Loop with an input of 10?
It will print numbers based on the logic set in the loop.
For counting down in a loop, what control structure can be used?
You can use a For Loop or a While Loop with decrementing condition.