1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mixer [17]
3 years ago
11

When do you use a while loop instead of a for loop? (Select multiple answers)

Computers and Technology
1 answer:
Alla [95]3 years ago
7 0

Answer:

1. You do not know how many times a loop will need to run

4. To repeat code.

Explanation:

Required

When to use while loop instead of for loop?

Option 1 and 4 answer the question

<em>1. You do not know how many times a loop will need to run </em>

Using while loop in this case is suitable to the for loop.

Take for instance

You want a set of instruction to be repeated until the user enters 1

e.g.

<em>while a != 1:</em>

<em>     print("abc")</em>

<em>     print("def")</em>

<em>     a = int(input("Input: "))</em>

<em />

The above is written in Python

The print instructions will be repeated until the user enter 1.

Now, you do not know if the user will enter 1 the first time or the 100th time or the 10000th time.

In other words, you don't know how many times the loop will be executed.

In this case, while loop is preferred to for loop

4. To repeat code:

The same analysis as used in (1) above is applicable in (4).

The print statements in

<em>while a != 1:</em>

<em>     print("abc")</em>

<em>     print("def")</em>

<em>     a = int(input("Input: "))</em>

will be repeated until the user enters 1

The for loop isn't preferable in this case

<em>Other options (2) and (3) can be implemented using both the for loops and the while loops</em>

You might be interested in
1. Flash Drive Price - An electronics company makes 64 gigabyte USB flash drives that cost them $8.00 apiece to produce. Write a
BaLLatris [955]

The programs are illustrations of sequential programs,

<h3>What are sequential programs</h3>

Sequential programs are programs that do not require loops (iterations) and conditional statements.

<h3>The flash drive program</h3>

The flash drive program written in C++ where comments are used to explain each line is as follows:

#include <iostream>

using namespace std;

int main(){

   //This calculates the selling price

   double sellingPrice = 8.00 * 1.35;

   //This prints the selling price

   cout<<"Selling price: $"<<sellingPrice;

   return 0;

}

<h3>The basketball program</h3>

The basketball program written in C++ where comments are used to explain each line is as follows:

#include <iostream>

using namespace std;

int main(){

   //This initializes the height in inches

   int heightInches = 75;

   //This prints the height in feet/inches

   cout<<"Height: "<<(heightInches/12)<<" feet, "<<(heightInches%12)<<" inches";

   return 0;

}

Read more about sequential programs at:

brainly.com/question/17970226

3 0
3 years ago
What is output?
Misha Larkins [42]

Answer:

The output of code will be 10

Explanation:

We need to find output of following code:

C = 1

Sum = 0

while (c less than 10):

C = c + 3

sum = sum + c

print (sum)

Solution:

We will check the condition of while loop, if the condition is true, then the statements inside the loop will be executed. Since brackets are not available so, only one statement is linked with while loop.

First while loop will be executed c < 10 (1<10) the condition becomes true, and statement c=c+3 will be executed ( 4=1+3) and then loop condition will be checked (4<10) the condition becomes true, and statement c=c+3 will be executed ( 7=4+3) and then loop condition will be checked (7<10) the condition becomes true and statement c=c+3 will be executed ( 10=7+3) and then loop condition will be checked (10<10) the condition becomes false, so we will come outside loop body and execute: sum=sum+c (10=0+10) and print sum i. e 10

So, The output of code will be 10

6 0
3 years ago
____ data refers to signals representing sound, temperature and car speed. These signals
taurus [48]

Answer:

digital

Explanation:

dspDigital signal processing (DSP) is the use of digital processing, such as by computers

8 0
3 years ago
A vast global network that is made up of many smaller interconnected networks is known as:
Galina-37 [17]

The answer is The Internet.   It is a vast global network that is made up of many smaller interconnected networks. It connects to millions of computer units world wide, in which any computer can communicate with any other computer as long as they are both connected to the Internet. It also made access to information and communication easier.

6 0
4 years ago
Read 2 more answers
Click cell i13 and calculate the agent commission using the base cost of the trip and a vlookup function that returns the commis
TiliK225 [7]
All you need to do is use excell.
5 0
3 years ago
Other questions:
  • Most input/output devices communicate with components inside the computer case through a wireless connection or through cables a
    8·1 answer
  • The main differences between laptops and desktop computers other than size and portability.
    14·1 answer
  • Design an information flyer about South Africa's driving regulations that will be given to the contestant of The Awesome Race 20
    7·1 answer
  • C# The video game machine at your local arcade output coupons according to how well you play the game. You can redeem 10 coupons
    8·1 answer
  • Jeremy is designing a website for a local pizza place. What is the appropriate resolution for him to set his images to?
    5·1 answer
  • Imagine you are building an ATM system; list at least 6 application domains for the system. That is, in which context is the sys
    13·1 answer
  • The commands available from a menu change depending upon what you are doing.<br> True<br> False
    11·2 answers
  • Which of the following statements about cover letters is false?
    14·2 answers
  • Which statement is true about hacking?
    11·2 answers
  • Why entity relationship model is used for data manipulation??<br><br>​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!