#include <iostream>
int main()
{
int i=0;
while( i<10 )
printf( "%d\n", ++i );
return( 0 );
}
int x = 1;
do {
if (!(x%2)) printf ("%d\n", x);
} while ++x<=10;
how to print "square" using for loop
unsigned count = 0;unsigned num=1; do { std::cout << num << std::endl; num +=2; } while (++count<50);
int i = 2; while (i <= 1000) { printf ("%d\n", i); i++; }
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.
Move the print out requesting the user to enter an integer outside of the for loop and it will only print once instead of each time around the loop. You'll need a way to save the even and odd numbers that you detect in the loop. One way is to have separate arrays to hold the even and the odd numbers as you go around the loop. Then at the end of the loop you can have more loops to print the contents of one array and then the contents of the other array. Another way is to concatenate the number onto separate Strings (even and odd) to be displayed after the data gathering loop.
c the book mastering c
x as int = 0 while x < 50 x = x + 1 print x endwhile
how to print "square" using for loop
int i=0; while (i++<n) { /*...*/ }
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.
In Python, you can create loops using different constructs, such as the for loop and the while loop. These loops allow you to repeatedly execute a block of code until a specific condition is met. Here's how you can create loops in Python: for loop: A for loop is used when you want to iterate over a sequence of elements such as a list, tuple, or string. It executes a block of code for each item in the sequence. for item in sequence: # Code block to be executed Here's an example that prints the numbers from 1 to 5 using a for loop: for num in range(1, 6): print(num) 2 while loop: A while loop is used when you want to repeat a block of code as long as a certain condition is true. It keeps executing the code block until the condition becomes false. while condition: # Code block to be executed Here's an example that prints the numbers from 1 to 5 using a while loop: num = 1 while num
cls input "enter a name"; a$ b=1 while b <=1 print a$ b = b+1 wend end
how do we use loops in c plus plus programing and what are basic differences between do,for and while loop
public static void main(String args){ int counter = 0; //initialize the counter variable to 0 while (counter < 10){ //while the counter variable is less than 10... counter ++; //increase the counter variable by 1 System.out.println(counter); //print the counter variable } }
unsigned count = 0;unsigned num=1; do { std::cout << num << std::endl; num +=2; } while (++count<50);
int i = 2; while (i <= 1000) { printf ("%d\n", i); i++; }
int main (void) { puts ("unique"); }