मराठी

Explain the working of the FOR statement with the help of an example program.

Advertisements

प्रश्न

Explain the working of the FOR statement with the help of an example program.

स्पष्ट करा
Advertisements

उत्तर

Working of the for Statement:

  1. Initialization: The loop control variable is initialized with a starting value. This step is executed only once.
  2. Condition: The specified condition is checked before each iteration. If the condition is true, the loop body is executed.
  3. Execution: The statements inside the for loop are executed when the condition is true.
  4. Updation: After each iteration, the loop control variable is updated, and the condition is checked again.
  5. Termination: When the condition becomes false, the loop terminates, and control passes to the next statement.

Example Program:

class ForExample
{
    public static void main(String[] args)
    {
        for (int i = 1; i <= 5; i++)
        {
            System.out.println(i);
        }
    }
}

Output:

1
2
3
4
5
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 7: Statements and their Scope - EXERCISE [पृष्ठ १६३]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
पाठ 7 Statements and their Scope
EXERCISE | Q 5. | पृष्ठ १६३
Advertisements
Share
Notifications



      Forgot password?
Use app×