For Loops for Beginners – ASP, C#, PHP, JavaScript & Python Examples

A “For Loop” executes a block of code a specific number of times or while a specified condition is true.

PHP For Loop

for (init; condition; increment)
  {
  code to be executed;
  }

php fOR lOOP PARAMETERS

  • init: Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop)
  • condition: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.
  • increment: Mostly used to increment a counter (but can be any code to be executed at the end of the iteration)

Note: The init and increment parameters above can be empty or have multiple expressions (separated by commas). Example The example below defines a loop that starts with i=1. The loop will continue to run as long as the variable i is less than, or equal to 5. The variable i will increase by 1 each time the loop runs:

PHP For Loop Example Code

<?php
for ($i=1; $i<=5; $i++)
  {
  echo("The number is " . $i . "<br>");
  }
?>

Classic ASP For Loop Example Code

<%
For i = 1 to 5
 Response.Write("The number is " & i & "<br>")
Next
%>

JavaScript For Loop Example

<%
For i = 1 to 5
 Response.Write("The number is " & i & "<br>")
Next
%>

C# For Loop Example

for (int i = 0; i < 5; i++) 
      {
        Console.WriteLine(i);
      }    

Python For Loop Example

states = ["Alaska", "Alabama", "Arkansas"]
for x in states:
  print(x) 
  if x == "Alabama":
    break

How to Share files between a Windows 7 PC and an iMac

I recently purchased a new Windows 7 Ultimate PC and an iMac.   This being my first Apple computer that I’ve ever owned I was really worried that I would not be able to have them talk to each other on the same network.

I was pleasantly surprised  that with some setup on the Windows 7 PC and a couple of commands on the iMac the sharing of files was a breeze.

Step 1: Make sure you have a work group defined for your home network on the Windows 7 PC.

  • To do this right click over Computer or My Computer
  • At the bottom of the System Properties window under Computer name, domain, and workgroup settings select “Change Settings”

Step 2: Setup file sharing on your Windows 7 PC.
If you need more help setting up Windows 7 file sharing check out this article from the How to Geek.

Step 3: Setup the share on your iMac.  Use  Command K then enter “smb:\\workgroup\pc_name”

Step 4: On the Network window make sure you have the same workgroup name entered here so that it matches your Windows 7 PC network workgroup.

Now when you open Finder on you Mac you will see your computer on left navigation bar listed under “Shared”.

You can also find some of this information on Apple’s support site.