System.out.println("After loop, i = " + i);</code></pre>
<p><code>i = 0</code> is the initializing statement</p>
<p><code>i < 3</code> is the conditional, that is when the loop ends</p>
<p><code>i++</code> is the increment/decrement</p>
<p><code>i++</code> is synonymous with <code>i = i + 1</code></p>
<p>The initialization statement only occurs once at the beginning of the loop. </p>
<h3>Execution Example</h3>
<p>Let us go through this for loop example</p>
<ul>
<li>Let us set <code>i = 0</code></li>
<li>Is <code>i < 3</code>? Yes execute the body
<ul>
<li>The body executes an output of <code>"i = 0"</code></li>
</ul></li>
<li>Now we increment <code>i ++</code>, i is now 1</li>
<li>Is <code>i < 3</code>? Yes, 1 is less than 3. Execute body
<ul>
<li>The computer prints out <code>"i = 1"</code></li>
</ul></li>
<li>Increment <code>i++</code> i is now 2</li>
<li>Is <code>i < 3</code>? Yes 2 is less than 3. Execute body
<ul>
<li>The computer prints out <code>"i = 2"</code></li>
</ul></li>
<li>Increment <code>i++</code>, i is now 3</li>
<li>Is <code>i < 3</code>? No 3 is not less than 3
<ul>
<li>Don't execute body of loop</li>
</ul></li>
</ul>
<p>Exit loop. Print <code>"After loop, i = 3"</code></p>
<h3>Condensing Syntax</h3>
<p>You can also do the declaration in the initialization statement</p>
<pre><codeclass="language-java">for (int i = 0; i < 3; i++) {
System.out.println("i = " + i);
}</code></pre>
<p>This now runs like above without the <code>"After loop, i = 3"</code> print. You cannot access the variable <code>i</code> outside the for loop since in this example, it belongs to the for loop's scope.</p>
<h2>Logic Expressions</h2>
<h3>And Statements</h3>
<p>With the AND operator <code>&&</code> both the left and right side needs to be true for the expression to be true.</p>