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?
1) Write a java programming nested while loop where you will declare two numbers one for...
1) Write a java programming nested while loop where you will declare two numbers one for outer loop and the other one for inner while loop, and display the result. (Try using scanner) Steps: 1) Declare the variable of outer loop int and assign value of your choice 2) Declare while condition which outer variable is less the number of your choice 3) Declare variable of inner loop int and assign the value of your choice 4) Declare while condition...
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)...