From ea4431bead43025630eb719ab70e01210db9bef0 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Mon, 26 Oct 2020 12:10:31 +0000 Subject: [PATCH] --- %D0%9E-%D1%86%D0%B8%D0%BA%D0%BB%D0%B0%D1%85.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 %D0%9E-%D1%86%D0%B8%D0%BA%D0%BB%D0%B0%D1%85.md diff --git a/%D0%9E-%D1%86%D0%B8%D0%BA%D0%BB%D0%B0%D1%85.md b/%D0%9E-%D1%86%D0%B8%D0%BA%D0%BB%D0%B0%D1%85.md new file mode 100644 index 0000000..b6b94eb --- /dev/null +++ b/%D0%9E-%D1%86%D0%B8%D0%BA%D0%BB%D0%B0%D1%85.md @@ -0,0 +1,7 @@ +Always use **FOREACH** when iterating over a whole array, or at least from the top of an array to a BREAK condition. This way you will never be bitten by an "off by one" error. + +Always use **FOR** when you know (or can easily determine) exactly how many times you need to execute the code in the loop. This is also useful for iterating parts of an array where you aren't always going to be starting from the head. + +Use a **DO-WHILE** when the number of times to have to execute the loop is indeterminate, but you know the code must execute at least once. + +Use a **WHILE** loop when the looping condition could be false as you enter the loop. In other words, there could be conditions where you never execute the loop. \ No newline at end of file