do while and for Helppppp | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

do while and for Helppppp

Exactly what happens when we use the for command once and then the while-do command again instead of while, I have seen changes, but I could not define them because I want to write notes and learn that. Please write notes about the change that is happening when I use for on the same code and do while, I get errors .. Please, when you answer me, answer me by writing the complete code Then, explain what happened because I do not know why errors appear Knowing the code is correct, but there is a problem with Solo Learn, please help me by using another code editor. It is preferred with writing comments on the code for explanation thank you https://code.sololearn.com/c8wEgCna7SO5

20th Nov 2020, 5:26 PM
STOP
STOP - avatar
6 Answers
0
https://code.sololearn.com/c27v0fOp331c my try
20th Nov 2020, 5:41 PM
STOP
STOP - avatar
0
In this 2nd code, you need this corrected statement to work exactly same as while of above code.. for ( ; number!=0; ) We use for loop when we know numbers of iterations needed prior the execution of code.. And syntax is for(intialization_part ; exit_condition ; increments/decrecents) {...} We use while on a condition true and upto condition becomes false.. while(condition) {...}
20th Nov 2020, 5:57 PM
Jayakrishna 🇮🇳
0
Iunderstood for and wrote it well, but I did not know write do while. When I write it, an error appears to me. Can you write it in code? Jayakrishna🇮🇳
20th Nov 2020, 6:01 PM
STOP
STOP - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input=new Scanner (System.in); System.out.println("Enter a number; or 0 to exit"); double sum=0; double number=input.nextDouble(); do{ sum+=number; System.out.println("Enter a number; or 0 to exit"); number=input.nextDouble(); }while(number!=0); System.out.println("The result is: "+sum); } } //Is this what you are looking..?STOP
20th Nov 2020, 6:05 PM
Jayakrishna 🇮🇳
0
Oh my friend I really don't know how to thank you, yeah that's what I'm looking for. You really helped me, I want you to write what your notes are on the output that appear in each of the while, for, do-while Jayakrishna🇮🇳
20th Nov 2020, 6:07 PM
STOP
STOP - avatar
0
1 2 3 4 5 6 7 8 9 10 0 In each code if i enter these above sample numbers it will give you output 55.0 It takes input of numbers upto you enter 0. add each number you enter to sum and display output sum. STOP
20th Nov 2020, 6:12 PM
Jayakrishna 🇮🇳