LOOPS EXPLANATION
LOOPS EXPLANATION
- We apply loops concept to decrease the size of our program.
- Loops run till the specified limit till which the condition is true.
- IF loop -> Checks the condition and then executes the instructions if the condition is true. SYNTAX- if ( a > b ) { printf("%d",a); }
- IF-ELSE loop -> If the condition is true then executes the condition under if or else executes the conditions under else. SYNTAX- if ( a > b ) { printf( "%d",a); } else { printf("%d",b); }
- SWITCH CASE -> These are used in scenarios where the user chooses an option and each option has different conditions.( eg- calculators)
- WHILE -> The loop runs till the condition is correct. It exits soon when the condition becomes false. SYNTAX- while ( i < 6 ) { printf( "%d",i); i++; }
- DO WHILE -> Executes the instructions once without checking the condition and then acts as a while loop from second time. SYNTAX- do { printf( " HI " ); } while ( condition );
- FOR LOOP -> Contains three parts- initialization, limit and increment or decrement. It is a commonly used loop. SYNTAX - for( i=0 ; i < 10 ; i++ ) { printf("%d",i); }
No comments:
Post a Comment