Posted by Jhon on Tuesday, November 1, 2011 at 3:02pm.
The while loop exits whenever a user-specified condition is reached, in this case when x≤4 or x≥10.
A for loops exits (normally) when the stated number of cycles is reached, i.e. not an arbitrary user condition.
There are different ways to "misuse" the for loop.
A common one is to create an infinite for-loop and make an independent exit condition, such as:
for(i=0;i<1000;i=i){ // this line actually compiles and runs in Java
// enter x
if(x<=4 || x>=10)break;
}
Another way to "force" a while loop capability in languages such as Java, C and C++ would be:
int x=5;
for(int i=0;x>4&&x<10;i++){ // bad style!
if(i>2)x=0; // or an input for x
System.out.println("printing");
}
But these are exceptional uses of the for-loop and are considered bad style, even the syntax is correct.
Related Questions
Computer Science (MATLAB) - I had a test in my computer science course in which ...
probability - out of 250 students interviewed at a community college, 90 were ...
CSC 111 Intruduction to Computer Science - What does it imply to pursue a ...
English - Let's write down what you can do with the computer. 1. I use the ...
computer science - write a program to select the classes that you are taking(Ex...
stsats - A researcher wanted to answer the following question: What is the ...
Statistics - I bemieve the t test is paired , want to make usre beofre I run the...
computer science - ineed help with c++. i am using code blocks and i have a ...
Stats - I ran this an an independent samples t-test. It is a t rest according to...
computer science - Hi what are mutator and accessor methods and what is the ...
For Further Reading