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
spin [16.1K]
3 years ago
9

When do you use a for loop instead of a while loop? (There may be more than one answer.)

Computers and Technology
1 answer:
statuscvo [17]3 years ago
8 0

Answer:

- You know how many times you want the loop to run.

- When there is a defined start and end.

Explanation:

Required:

When to use for instead of while loop?

First, it should be noted that both for loop and while loop are used for iteration. However, depending on the scenario; there is preference on one to the other.

The basic syntax of for loop is:

for(start;end;condition)\{\}

<em>The condition could either be increment or decrement</em>

The basic syntax of while loop is:

while(condition)\{\}

<em>The condition could be any condition whatsoever</em>

Analyzing the options one after the other.

1. How many times the loop to run.

The for loop is preferred here because of the simplicity of the for loop.

2. & 3. Both the for and while loops are used for code repetition and to perform number calculations

4. Defined start and end.

From the syntax of the for loop

for(start;end;condition)\{\}

<em />

A for loop has a definite start and end in its basic syntax and is more preferable to use instead of a while loop.

<em />

<em />

Hence, 1 & 4 answer the question

You might be interested in
If 209g of ethanol are used up in a combustion process, calculator the volume of oxygen used for the combustion at stp​
SOVA2 [1]

Answer:

a) The volume of oxygen used for combustion at STP is approximately 305 dm³

b) The volume of gas released during combustion at STP is approximately 508 dm³

Explanation:

The given chemical reaction equation for the burning of ethanol in air, is presented as follows;

2CH₃CH₂OH (l) + 6O₂ (g) → 4CO₂ (g) + 6H₂O

The mass of ethanol used up in the combustion process, m = 209 g

The molar mass of ethanol, MM = 46.06844 g/mol∴

The number of moles of ethanol in the reaction, n = m/MM

∴ n = 209 g/(46.06844 g/mol) ≈ 4.537 moles

a) Given that 2 moles of ethanol, CH₃CH₂OH reacts with 6 moles of oxygen gas molecules, O₂, 4.54 moles of ethanol will react with (6/2) × 4.537 = 13.611  moles of oxygen

The volume occupied by one mole os gas at STP = 22.4 dm³

The volume occupied by the 13.611 moles of oxygen gas at STP, 'V', is given as follows;

V = 13.611 mol × 22.4 dm³/mole = 304.8864 dm³ ≈ 305 dm³

The volume occupied by the 13.611 moles of oxygen gas at STP, V = The volume of oxygen used for the combustion ≈ 305 dm³

b) The total number of moles of gases released in the reaction, is given as follows;

The total number of moles = (4.537/2) × (4 + 6) = 22.685 moles of gas

The total volume of gas released, V_T = The volume of gas released during the combustion at STP = 22.685 moles × 22.4 dm³/mole = 508.144 dm³ ≈ 508 dm³

7 0
3 years ago
Sometimes we write similar letters to different people. For example, you might write to your parents to tell them about your cla
OleMash [197]

?

?????????????????????

4 0
3 years ago
Explain with the help of an example that family background affects the entrepreneurial behaviour of people
marta [7]

Answer:

Like other aspects, family background also affects the entreptrneurial behaviour of people as entrepreneurship directly depends on people and people are affected to big extent by the family background.

Explanation:

  • According to the research statistics 25% of the variation in decisions of individuals to become employed to self is explained by family background and influence of the community.
  • It also suggested that the entrepreneurship depends upon sibling correlation and shared genes.
  • It is greatly affected by characteristics of parents and family members including sibling peer effects, income, education, self employment, neighbourhood effects and incorporation.
3 0
3 years ago
I need a C++ program to ask the user to put in different numbers until zero is pressed then the program counts the numbers that
frozen [14]

Answer:

#include <iostream>

using namespace std;

int main()

{

int input = 0;

int count = 0;

int sum = 0;

int sumNegative = 0;

while (true) {

 cout << "Enter a number: ";

 cin >> input;

 if (input == 0) break;

 count++;

 sum += input;

 if (input < 0) {

  sumNegative += input;

 }

}

cout << "Count of the numbers: " << count << endl;

cout << "Sum of all the numbers: " << sum << endl;

cout << "Sum of the negative numbers: " << sumNegative << endl;

}

Explanation:

Your requirements regarding the sum and the negative numbers was a bit vague so I just did something you can probably adjust easily to your liking.

7 0
3 years ago
Write a repetition statement that outputs the numbers 45 , 51 , . . . , 165 . That is, all of the multiples of 6 in increasing o
Bingel [31]

Answer:

#include <iostream>

using namespace std;

int main()

{

   int i = 45;

   for ( i = 45; i <=165; i = i + 6)

       cout << i << endl;

}

Explanation:

I corrected your code and highlighted the mistakes. Even though you wrote the correct algorithm, your code did not compile because of the typos you made.

Remember, C++ is a case-sensitive language. That means, "For" is not same as "for".

Generally, variables and keywords are written in lower case. Of course, there are exceptions, such as constant variables are all written in uppercase letter and class names start with an uppercase letter.

8 0
3 years ago
Other questions:
  • When did Kodak introduce film photography to the commercial market?
    10·2 answers
  • Every node (except of the last node) in a singly linked list contains ____
    5·1 answer
  • In the accompanying figure, the split double arrow mouse pointer____.
    7·1 answer
  • Fill in the blanks. The ________________ donut chart shows the distribution across your website’s pages by the number of clicks
    14·1 answer
  • Services such as water, electricity, and phone communications are called:
    7·1 answer
  • A system analyst generally needs to have a number of skills. For example, technical and analytical skills are required for this
    7·1 answer
  • Use the drop-down menus to complete statements about audio file formats.
    10·1 answer
  • Select the correct answer
    15·1 answer
  • What would the input, process, outcome and feedback be for a class assignment
    10·1 answer
  • Suppose your team is finishing a project and the supervisor stresses ensuring the material cannot be erased. To what memory leve
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!