5 Replies - 804 Views - Last Post: 22 February 2011 - 05:10 AM Rate Topic: -----

#1 Titwhisperer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 21-February 11

For loops and nested For loops

Posted 21 February 2011 - 06:41 AM

I'm having difficulty transitioning to c# from VB in the sense that I don't seem to catch on to For loops and their syntax. I have written several successful programs using them in VB, but it seems more difficult in C#....is there a little trick to remembering the code?
Is This A Good Question/Topic? 0
  • +

Replies To: For loops and nested For loops

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,605
  • Joined: 23-August 08

Re: For loops and nested For loops

Posted 21 February 2011 - 06:53 AM

MSDN entry for a for loop

What exactly don't you understand?
Was This Post Helpful? 0
  • +
  • -

#3 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: For loops and nested For loops

Posted 21 February 2011 - 07:13 AM

The syntax is very different, but the functionality is still the same.
for (int x = 0; x < blah; x++)
{
    // do something...
}



You have a variable, whether declared in the loop or elsewhere, given a value of 0. The value of that variable is checked against whatever you decide to check it against, in this case is x less than blah, if it is, then increment x and drop into the loop and perform the logic therein. Once the code inside the loop has done it's thing, we drop back to the conditional statement of the loop to check if x is still less than blah. Repeat this process until x is no longer less than blah.

This post has been edited by Kilorn: 21 February 2011 - 07:14 AM

Was This Post Helpful? 0
  • +
  • -

#4 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: For loops and nested For loops

Posted 22 February 2011 - 03:43 AM

you can view the stucture of the for loop and how it works

follow this link

http://www.youtube.c...h?v=n2VyNzIOA8Y

This is very easy


for(int [variable] = [value]; [value] <= [initialization number]; [increment value]++)
{
//Do loop until initialization number is reached
}

This guy explains the loop

http://www.youtube.c...h?v=0ru5ZPigtI0

Its better than vb6 loops

Hope this helps

This post has been edited by marinus: 22 February 2011 - 03:56 AM

Was This Post Helpful? 0
  • +
  • -

#5 Titwhisperer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 21-February 11

Re: For loops and nested For loops

Posted 22 February 2011 - 04:49 AM

Hey dude,
This was a help....I know the basics of loops, but there are now {} and all sorts of other differences from VB. This is what I'm in class for I guess huh...I thank you for your help and I might ask a question or two in the future. Have patience...I'm back in school after30 years and I believe my brain is refusing to go quietly!
Thx,

Chris
Was This Post Helpful? 0
  • +
  • -

#6 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: For loops and nested For loops

Posted 22 February 2011 - 05:10 AM

No problem

If my post helped to you please mark " Was This Post Helpful " and rate it

then well all be happy :)

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1