If you mean you cannot use a for loop, then use a while loop:
int i=0
while( i++ < 100 )
std::cout << i << " ";
std::cout << std::endl;
Or a do-while loop:
int i=0;
do
std::cout << ++i << " ";
while( i<100 );
std::cout << std::endl;
If these are not allowed either, use a procedural loop:
int i=0;
again:
std::cout << ++i << " ";
if( i<100 ) goto again;
std::cout << std::endl;
If even that is not allowed, then the only option is to hard-wire:
std::cout << 1 << " " << 2 << " " << [etc] << 99 << " " << 100 << std::endl;
It does seem a pointless exercise when a for loop exists specifically for counting iterations like this:
for( int i=1; i<=100; ++i )
std::cout << i << " ";
std::cout << std::endl;
how to print "square" using for loop
The best way to print the numbers 1 to 100 in PHP without using a loop is with the following code: echo implode("<br>", range(1,100)); You can replace the <br> with anything that you want to separate the numbers, such as dashes. I used a line-break in the example.
If you are using for loop for(;;); or you can also define condition and iterations but the loop has to close there itself without any statement inside it. In the similar way you can define while and do while loop without any statement.
while- It will wrok only if the condition is correct if not it wont excute the body of the loop do-while: In some cases we want that body of the loop and the condition may fails so the loop want to print so the do while loop first excute body of the loop and next it checks the condition it continues until the condition becomes false
var fruits = ["Banana", "Orange", "Apple", "Mango"]; var x=fruits.valueOf(); alert(x);
int youArray[arraysize] = {...};...for (int i = 1; i
int main (void) { puts ("unique"); }
To determine how many times the loop will print "hello," I would need to see the specific code for the loop. The number of iterations depends on factors like the loop's initialization, condition, and increment or decrement statements. Please provide the loop code for an accurate answer.
The do..while() loop tests the condition at the end of the loop. Therefore the loop body executes at least once. The while() loop (without do) tests the condition before entering the loop and before each iteration of the loop. The for() loop conditional expression is optional but, when specified, is tested before entering the loop and before each iteration of the loop.
It may not be worthwhile to write a loop at all in such a simple case. On the other hand, you can make two loops, one for the ascending part, and one for the descending part. Finally, you can use a single loop, and a condition inside it: use a counter "i" = 1 to 5; if i < 4 print i, otherwise print 6 - i. This latter would be useful if, instead of simply printing the values indicated, you needed several commands within the loop; in this case, having a second loop is simply not practical.
foreach can simply replace for loop. for ex in perl, if you need to copy display an array, it will take only foreach $var(@arr). then print $var. no need of incrementing the index of array like for loop.
All loops available in Java (for, while, do-while) have a loop termination condition that would get executed during every iteration of the loop. Without checking the loop condition the loop cannot be terminated and hence avoiding the loop condition check during iteration is not logic and Java does not do it.