The document discusses for loops in Java. It explains that a for loop allows iterating over a range of values using an initialization expression, termination expression, and increment expression. An example prints the numbers from 0 to 9 using a for loop. Another example prints a multiplication table from 1 to 10 using nested for loops.
The document discusses for loops in Java. It explains that a for loop allows iterating over a range of values using an initialization expression, termination expression, and increment expression. An example prints the numbers from 0 to 9 using a for loop. Another example prints a multiplication table from 1 to 10 using nested for loops.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online from Scribd
The document discusses for loops in Java. It explains that a for loop allows iterating over a range of values using an initialization expression, termination expression, and increment expression. An example prints the numbers from 0 to 9 using a for loop. Another example prints a multiplication table from 1 to 10 using nested for loops.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online from Scribd
For Loop • The for statement is a compact way to iterate over a range of values. • Syntax: for (InitializationExpression; TerminationExpression; IncrementExpression ) { statement1; statement2; } For Loop • The initialization expression initializes the loop. It sets the initial value of the variable that will be used to control the loop. • The termination expression represents the loop condition, which is evaluated after each iteration. As discussed previously, when the loop condition evaluates to false, the loop terminates. • The increment expression is executed after each iteration. It may increment or decrement the variable set in the initialization expression. Sample problem: For Loop public class Act1{ public static void main (String[]args){ for ( int i=0; i<10; i++){ System.out.print(“ “ + i); } } } Output:
• -------Configuration: <Default>------------ • 0123456789 • Process completed. For Loop • The example below displays the multiplication tables from 1 to 10.