Warning: Cannot modify header information - headers already sent by (output started at /home/n742ef5/public_html/forum/index.php:3) in /home/n742ef5/public_html/forum/wp-content/plugins/asgaros-forum/includes/forum-online.php on line 80

Warning: Cannot modify header information - headers already sent by (output started at /home/n742ef5/public_html/forum/index.php:3) in /home/n742ef5/public_html/forum/wp-content/plugins/asgaros-forum/includes/forum-unread.php on line 43

Warning: Cannot modify header information - headers already sent by (output started at /home/n742ef5/public_html/forum/index.php:3) in /home/n742ef5/public_html/forum/wp-content/plugins/asgaros-forum/includes/forum-unread.php on line 82
Understanding For Loop Google apps script tutorial for beginners – 9 – Sithtamil – My Notes

Forum

Please or Register to create posts and topics.

Understanding For Loop Google apps script tutorial for beginners - 9

It is one of the fundamental loop constructs used for repetitive tasks in programming. The key components of a for loop typically include an initialization, a condition, an iteration, and the code block to be executed.

for (initialization; condition; increment )
{
// Code to be executed repeatedly
}

for (var i = 1; i <= 5; i++) {
Logger.log(i);
}

Initialization: This part is typically used to initialize a loop control variable, often a counter. It sets the initial value of the variable before the loop starts.

Condition: This is a boolean expression that is evaluated before each iteration of the loop. If the condition is true, the loop continues to execute; if it's false, the loop terminates.

increment : This part is responsible for changing the loop control variable's value after each iteration. It determines how the loop moves toward its termination condition.

Code Block: The code block contains the statements that you want to execute repeatedly as long as the condition is true.

for (var i = 1; i <= 5; i++) {
Logger.log(i);
}

var i = 1 initializes the loop control variable i to 1.
i <= 5 is the condition. As long as i is less than or equal to 5, the loop continues.
i++ increments i by 1 after each iteration.
console.log(i) is the code block that logs the current value of i.