answersLogoWhite

0

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;

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

How do you print square using for loops?

how to print "square" using for loop


How do you print 1 to 100 without using loop in php?

The best way to print the numbers 1 to 100 in PHP without using a loop is with the following code: echo implode("&lt;br&gt;", range(1,100)); You can replace the &lt;br&gt; with anything that you want to separate the numbers, such as dashes. I used a line-break in the example.


How can you define null statement in loop in C programming?

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.


What are the differences between while and do while?

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


How do you print an array in JavaScript without using a loop?

var fruits = ["Banana", "Orange", "Apple", "Mango"]; var x=fruits.valueOf(); alert(x);


How to print the reverse of an array without using backward loop?

int youArray[arraysize] = {...};...for (int i = 1; i


To print unique no using for loop?

int main (void) { puts ("unique"); }


How many times will the following loop print the word hello to the screen?

To determine how many times the loop will print &quot;hello,&quot; 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.


What looping process checks the test condition at the end of the loop?

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.


How can you print 1 2 3 2 1 using for 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 &lt; 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.


What are the advantages of using a foreach loop over a for or while loop for processing list elements?

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.


Which Loop avoids check at every iteration?

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.