0
I there any way to execute a statement for one time only , when all values in for loop or satisfying the condition.
for (int x=0 ; x《length.array ; x++ ) If (array [x] 》 array [x+1] ) Statement. out.println (array [x] +" is largest");
1 ответ
+ 1
To create a loop that runs once only you need to set a condition upon which the loop should terminate, the following snippet shows a one iteration loop.
I hope I got your question correctly, you didn't specify a language in the question tag, but looking at your code I just guessed it was Java.
public class Program
{
public static void main(String[] args) {
// This loop runs once only
for(int i = 1; i <= 10; i++)
{
System.out.println("Iteration " + i);
if(i < ++i)
{
System.out.println("Condition satisfied");
break;
}
}
}
}
Hth, cmiiw