Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Loops
- printf("%d",1); Loop provision
- printf("%d",1);
- printf("%d",1);
- printf("%d",1);
- printf("%d",1);
- Loop
- > While
- > for
- > do while
- WHILE LOOP
- ==========
- while(condition)
- {
- while body;
- }
- a=1;
- while(a<=5)
- (
- )
- Infinite Loop. There is no increment.
- To run a Loop we need to increase the count each time.
- a=1;
- while(a<=5)
- (
- a=a+1;
- )
- a=1;
- while(a<=10)
- (
- a=a+2;
- ) 5 Times
- a=5;
- while(a<=1)
- (
- a=a-1;
- ) 0 TIMES
- a=5;
- while(a>=1) A= 5 - 0 Big to Small (-) (>)
- ( A=0 - 5 Small to Big (+) (<)
- a=a-1;
- )
- Loop is otherwise called Iteration.
- a(variable) is Iterator.
- a=1;
- while(a<=5)
- {
- printf("%d",1);
- a=a+1;
- } O/P : 11111
- printf("%d",1);
- printf("%d",2);
- printf("%d",3);
- printf("%d",4);
- printf("%d",5);
- ***************************
- a=1;
- while(a<=5)
- {
- printf("%d",a);
- a=a+1;
- } O/P : 12345
- ******************************
- a=5; a 5 4 3 2 1
- while(a<=5) 1 2 3 4 5
- {
- printf("%d", 6-a );
- a=a-1;
- } O/P : 12345
- **************************
- a=5;
- while(a>=5)
- {
- printf("%d",a);
- a=a-1;
- }
- -----------------------
- a=b=1;
- while(a)
- {
- } Valid
- ---------------------------------------
- a=b=1;
- while(a)
- {
- a=b<=3;
- printf("%d %d \n", a, b);
- b=b+1;
- }
- printf("%d %d \n",a+10,b+10);
- O/p : 1 1
- 1 2
- 1 3
- 0 4
- 10 15
- -------------------------------------------
- a=b=10;
- while (a)
- {
- a= b < = 13;
- printf("%d %d \n",a,b );
- b=b+1;
- }
- printf("%d %d \n",a+10,b+10);
- //////////////////////////////////////////////////////
- -----------For Loop-----------
- for(intialization; Condition; increment or decrement)
- {
- for body;
- }
- *****************************
- void main()
- {
- int a;
- for(a=1;a<=3;a=a+1) a=1 2 3 4
- {
- printf("a");
- }
- } O/P : aaa
- *****************************
- int a,b;
- for(a=1,b=10;a<=b; a=a+1,b=b+1)
- {
- printf("%d %d ",a,b);
- }
- printf("%d %d ",a+10,b+10);
- O/P : 1 10 2 9 3 8 4 7 5 6 16 15
- *******************************
- int a,b;
- for(a=b=1; a ;b=b+1)
- {
- a=b<=3;
- printf("%d %d ",a,b);
- }
- printf("%d %d ",a+10,b+10);
- O/P :
- *******************************
- void main ()
- {
- for( ; ; ) Valid...
- {
- printf("Hello"); Infinite times Hello
- }
- }
- Condition Will be true if it is empty
- ********************************
- void main()
- {
- int a=1;
- for( ;a<=3; )
- {
- printf("%d"a);
- a=a+1;
- }
- }
- }
Add Comment
Please, Sign In to add comment