1 How are indefinite loops used for validating data Why is a
1. How are indefinite loops used for validating data? Why is a loop structure typically the better choice for validating data than an if statement?
2. while(10 > 1){
System.out.println(\"This prints forever.\"); }
Identify the problem that exists in the above while loop.
3. Why would a programmer use curly braces in the body of a do…while loop?
Solution
1. Basically indefinate loop which is also know as while trap is a very smart piece of code we are basically used indefinate loop when constraint value or value till which loop will be executed is not known to us so we use a constant value which never change or a variable in which we store a constant or true value.
2. In my compiler your file returns end of file before completely execute while loop so there is a problem you can you following code instead of that one
while(10>1)
{
System.out.println(\"this prints forever\");
}
3. A statement ends either with two conditions
a-block ending(delimeters)
b-with semicolon- ;
In Do-While statement-\"do this while this\" is a single statement, and can\'t end with a block (because it ends with the \"while\"), so it needs a semicolon just like any other statement.
| |
