Using for Loop and Questions

 The for Loop Construct:

The for loop construct is far superior and more powerful than the loop constructs provided by the language. The construct provides a compact way of specifying the statements the statements that control repetition of the steps within the loop.

Syntax: for(starting_value ; ending range ; increment/decrement)

Example 1: Leap year within range



Example 2: Table for 2

 

Example 3: Table from 2 to 20



Example 4:prime number user defined

 



 Example 5: factorial


 

 Example 6: pattern left side star

*
* *
* * *
* * * *
* * * * *
 

 

 

 Example 7: inverted pattern left side star

* * * * *
* * * *
* * * 
* *
*
 

 

 Example 8: star pyramid


        *
      * * *
    * * * * *
  * * * * * * *
* * * * * * * * *
 

 


Example 9: inverted pyramid

* * * * * * * * *
  * * * * * * *
    * * * * *
      * * *
        *
 

 

 Example 10: hollow diamond star pattern

**********
****  ****
***    ***
**      **
*        *
*        *
**      **
***    ***
****  ****
**********
 
 
Code:


Output:






Comments