Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- loops_in_c.c by Dragan Milicev
- There is no difference between loops in C,
- except that the do-while loop must be performed at least once.
- for loop
- https://www.tutorialspoint.com/cprogramming/c_for_loop.htm
- for ( init; condition; increment ) {
- statement(s);
- }
- while loop
- https://www.tutorialspoint.com/cprogramming/c_while_loop.htm
- init;
- while(condition) {
- statement(s);
- increment;
- }
- do-while loop
- https://www.tutorialspoint.com/cprogramming/c_do_while_loop.htm
- init;
- do {
- statement(s);
- increment;
- } while( condition );
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main(void)
- {
- int i, n=3;
- for( i=0; i<n; i++ ) // ( init; condition; increment )
- printf("\n for loop: i = %d \n", i ); // statements
- i=0; // init
- while ( i<n ) // condition
- {
- printf("\n while loop: i = %d \n", i ); // statements
- i++; // increment
- }
- i=0; // init
- do
- {
- printf("\n do-while loop: i = %d \n", i ); // statements
- i++; // increment
- } while ( i<n ); // condition
- return 0;
- }
Advertisement
RAW Paste Data
Copied
Advertisement