Thursday, November 24, 2011

Looping Without Loop in C Programming

‎In c programming we made loop with help of conditional statements.The conditional statements use for looping in c programming are IF LOOP , WHILE LOOP and DO WHILE LOOP.

How many of us can make looping without using any conditional statements mentioned above.If i asked you guys to make looping program without using any conditional statements then you guys will ask me umm there is possible to do looping without using conditional.I also think that before i found this program and i don’t believe.But when i compile this code, I am enforce to believe it.

   1: //looping without default loops(if, do, while, for)
   2: #include<stdio.h>
   3: #include<stdlib.h>
   4: void (*func[2])(int);
   5: void main(int n)
   6: {
   7:           int i;
   8:           printf("\n %d",n);
   9:           func[0]=&exit;
  10:           func[1]=&main;
  11:           i = ++n <= 10;
  12:           (func[i])(n);
  13: } 



Another method for looping without using any loop in c programming is



   1:///this concept is also good 
   2:  
   3: #include <stdio.h>
   4: #include <stdlib.h>
   5: void main(int j) {
   6:          printf("%d\n", j);
   7:          (&main + (&exit - &main)*(j/1000))(j+1);
   8: }

No comments:

Post a Comment