Question

What are the semantic differences between a for loop and a while loop? Can you convert...

What are the semantic differences between a for loop and a while loop? Can you convert a while loop to an equivalent for loop and vice versa? If so, how?

Java

Homework Answers

Answer #1

/*If you any query do comment in the comment section else like the solution*/

For Loop:
for(initialization; condition; increment/decrement) {
//statments
}
eg:
for(i=0;i<10;i++) {
//TODO
}

While Loop:
initialization
while(condition) {
//TODO
increment/decrement
}

i = 0;
while(i < 10) {
//TODO
i++;
}

Also you can see that I've written same loop repeating from i = 0 to 10 using semantics of both for and while so it is possible to convert a while loop to a for loop and vice versa

Know the answer?
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
Similar Questions
What are the differences between a for loop and a while loop in shell scripting? Provide...
What are the differences between a for loop and a while loop in shell scripting? Provide Examples. -- UNIX/LINUX
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop to complete the task. A while loop has this basic structure: /* variable initializations */ while (/*stop condition*/){ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } Despite the structure of the while loop being different than that of a for loop, the concept behind it is...
What is the differences between groups and teams? How do we convert a group to a...
What is the differences between groups and teams? How do we convert a group to a team? What benefits might come from this conversion in a business environment?
Can you rewrite this MATLAB code using a while loop instead of a for loop? %formatting...
Can you rewrite this MATLAB code using a while loop instead of a for loop? %formatting clc, clear, format compact; %define variables k=1; b=-2; x=-1; y=-2; %while loop initialization for k <= 3 disp([num2str(k), ' ',num2str(b),' ',num2str(x),' ',num2str(y),]); y = x^2 -3; if y< b b = y; end x = x+1; k = k+1; end
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
What is the purpose of an expression in a loop statement? What is the difference between...
What is the purpose of an expression in a loop statement? What is the difference between a while loop, and a do/while loop?
What struck you as the key differences between rigid and flexible cultures? How can you use...
What struck you as the key differences between rigid and flexible cultures? How can you use this information when doing business cross culturally?
What are the main differences between theoretical and experimental probability? How can you tell which one...
What are the main differences between theoretical and experimental probability? How can you tell which one is being used in a scenario? Provide examples that highlight the differences between the two types. Your post must have a minimum of 5 sentences.
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Can i get the answer to these questions in detail explaining how you go to the...
Can i get the answer to these questions in detail explaining how you go to the solution 1.Convert to/from Hex (0) 2.Octal Binary Unsigned/ 2’s complement 3.Understand how to shift and rotate. 4.Understand the relationship between shifting and multiplication/division 5.Be able to recognize and use the following gates: AND OR NOT NAND NOR XOR 6.Understand how a half adder works Given a logical statement ((A OR B) AND NOT(C OR A)) show the gates. 7.What is the difference between an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT