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 to print the reverse of an array without using backward loop?

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


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

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


To print unique no using for loop?

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


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.


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.


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.


Do statement and For statement comparisons?

Do statement : Here the do loop exicutes once without cheching the condition and then the condition will be checked if condition becomes true then again loop begins from do and then exictes here if you are given value is n then loop exictues n+1 times.for statement : Here the for loop will be initilized first and the condition will be checked if the condition then the pointer enters the loop else not.And after completion of the loop the pointer again moves to the for statement and the increment/Decrement will be done as you provided in loop then the condition will be checked if satisfy then it enteres loop else not