Question

rewrite this post and code their for loops as while loops. The only thing I need...

rewrite this post and code their for loops as while loops. The only thing I need to see in the while loop body is a statement that would change the loop counter as the for loop statement would.

for (cars = 70; cars < 86; cars++)

{

}

for (planes = 75; planes >= 0; planes--)

{

}

for (trains = 0; trains < 100; trains += 4)

{

}

Part 2: I used my third for loop

do

{

trains += 4;

}

while(trains < 100);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

cars = 70;

while (cars < 86)
{
   cars++;
}

planes = 75;
while (planes >= 0)
{
   planes--;
}

trains = 0;
for (trains < 100)
{
   trains++;
}

Add a comment
Know the answer?
Add Answer to:
rewrite this post and code their for loops as while loops. The only thing I need...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MATLAB You've recently looked at 'while' loops in Matlab. Break statements can be contained within 'while'...

    MATLAB You've recently looked at 'while' loops in Matlab. Break statements can be contained within 'while' loops to exit the loop early. Look at the following example code: x=-10; while x<0       x=x+2;      if x == -2             break;       end end Without the break statement, the while loop would usually add 2 to x=-10 until x=0, and then produce a final answer of x=0 at the end of the loop. Now, the loop ends prematurely when the value of...

  • 2. Rewrite the following loop into a while loop statement: (4 Marks) (CLO2:PLO5:C2) int i, b;...

    2. Rewrite the following loop into a while loop statement: (4 Marks) (CLO2:PLO5:C2) int i, b; cout<<"Please enter the lower bound of the loop:\n"; cin>>b; for (i = 70; b = i; i--) cout << i << endl; CSCS1511/March2019 Page 4 of 6

  • Need in Python! Consider the following program and expected output. Rewrite it using a for loop...

    Need in Python! Consider the following program and expected output. Rewrite it using a for loop and a conditional break statement such that it has the same output.   HINT: Stay with i as the main loop counter and let j control the break behavior.   i = 0 while i < 10 and j < 10 : j = i * 2 print(i, j) i += 1 # Output below, for reference - not part of the program! 0 0 1...

  • Rewrite the if statement below using only the relational operator < in all conditions

     53.  Rewrite the if statement below using only the relational operator < in all conditions. Assume that the value of score is between 0 and 100 inclusive. 54.  Rewrite the following code segment as an equivalent segment that uses a do-while statement. 55.  Assuming the following declaration: char my array[9] - ['C', 'p', 't', 'S', '9, '1', '2', '1']; What is the value of*(my array +4)?

  • Control Structures and Subroutines I. A while loop whose condition is not made false is called...

    Control Structures and Subroutines I. A while loop whose condition is not made false is called an infi nite loop. However, it is infinite, in the sense of continuing to run forever, only in theory. The loop will stop at some point. Why? 2. To evaluate the if statements in this question below, assume that a Print statement simply prints whatever is in quotes after it. The phrases after a semicolon in the third code fragment are comments and are...

  • A) Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume...

    A) Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume that all the variables are declared and initialized. k-G+ 13)/27 loop: if k> 10 then goto out k=k+1 i=3"k-1 goto loop I out: B) Rewrite the following code segment in C++ using the multiple-selection (switch and if-else) statements. Assume that all the variables are declared and initialized. if((k 1) || (k 2))j-2 k-1 if ((k 3) || ( ks))j - 3.k+1 if (k 4)j-4k-1...

  • Rewrite the if statement below using only the relational operator < in all conditions

     Rewrite the if statement below using only the relational operator < in all conditions. Assume that the value of score is between 0 and 100 inclusive. Rewrite the following code segment as an equivalent segment that uses a do-while statement. Assuming the following declaration: char my array[9] = ['C', 'p', 't', 'S', '', '1', '2', '1'); What is the value of *(myarray, + 4)? What will be the values of k[1], k[2], and k[3] after execution of the code segment below assuming the input data shown?

  • Part 1: Python code; rewrite this code in C#, run the program and submit - include...

    Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...

  • I need this code in java. Loops do just what they sound like they should -...

    I need this code in java. Loops do just what they sound like they should - they perform a statement again and again until a condition is fulfilled. For this lab you will be practicing using loops, specifically a for loop. The for loop takes the form of: for(/*variable initialization*/;/*stop condition*/; /*increment*/){ //statements to be done multiple times } Task Write an application that displays every perfect number from 2 through 1,000. A perfect number is one that equals the...

  • (1 point) Using an if Statement In a Loop A common thing to do is to...

    (1 point) Using an if Statement In a Loop A common thing to do is to use variables to keep track of some sort of count. When used in a loop we count things very quickly. Scenario: If you roll a pair of dice, rolling a 12 (two sixes) is rare. How rare? If you were to roll a pair of dice 1,000 times, on average, how many times would it come up as 12? To figure this out, we...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT